Library
penvm.lib.base
Provide BaseObject
for all PENVM classes that need its
functionality.
BaseObject
Base object for PENVM classes.
Provides common support for oid
(UU object id) and
object-specific LoggerAdapter
logger.
Source code in penvm/src/lib/penvm/lib/base.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
__init__(oid, logger)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
oid |
str
|
Universally unique object id. |
required |
logger |
Logger
|
Logger to wrap with |
required |
Source code in penvm/src/lib/penvm/lib/base.py
36 37 38 39 40 41 42 43 44 |
|
penvm.lib.connection
Wrappers for low-level connections.
ClientConnection
Bases: Connection
Client-side message queue connection.
Source code in penvm/src/lib/penvm/lib/connection.py
627 628 629 630 631 632 633 634 635 636 |
|
__init__(*args, **kwargs)
Initialize.
Source code in penvm/src/lib/penvm/lib/connection.py
630 631 632 633 634 635 636 |
|
Connection
Bases: MessageConnection
Connection.
Provides the interface between the network socket and message queues (incoming, outgoing).
The headers of incoming and outgoing message are all augmented with the connection id.
Source code in penvm/src/lib/penvm/lib/connection.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|
__init__(machine, host, port, sslcontext=None, sock=None, onclose=None)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
machine |
Machine
|
Machine. |
required |
host |
str
|
Host address. |
required |
port |
int
|
Port. |
required |
sslcontext |
Union[SSLContext, None]
|
SSL Context. |
None
|
onclose |
Union[Callable, None]
|
Function to call to when connection is closed. |
None
|
Source code in penvm/src/lib/penvm/lib/connection.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
close()
Close connection.
Source code in penvm/src/lib/penvm/lib/connection.py
485 486 487 488 489 490 491 492 493 494 495 496 497 |
|
imq_put(msg)
Put message on IMQ.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
Message
|
Message to enqueue. |
required |
Source code in penvm/src/lib/penvm/lib/connection.py
499 500 501 502 503 504 505 506 507 508 |
|
recvmsgs()
Receive messages over connection.
Loops while self.exit
is True
.
Source code in penvm/src/lib/penvm/lib/connection.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
sendmsgs()
Send message over connection.
Loops while self.exit
is True
.
Source code in penvm/src/lib/penvm/lib/connection.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
|
start()
Start recv and send message handing.
Source code in penvm/src/lib/penvm/lib/connection.py
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 |
|
state()
Get object state.
Returns:
Type | Description |
---|---|
State
|
|
Source code in penvm/src/lib/penvm/lib/connection.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 |
|
Listener
Bases: BaseObject
Listener side/socket.
Source code in penvm/src/lib/penvm/lib/connection.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
listen(n=1)
Set up to listen for connection.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
Number of outstanding socket connection requests allowed. |
1
|
Source code in penvm/src/lib/penvm/lib/connection.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
settimeout(delay)
Set timeout.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delay |
int
|
Seconds before timing out on idle connection. |
required |
Source code in penvm/src/lib/penvm/lib/connection.py
135 136 137 138 139 140 141 142 143 144 |
|
MessageConnection
Bases: SocketConnection
Message connection.
Provides the interface to the socket with support for messages.
The headers of incoming and outgoing message are all updated with the connection id.
Source code in penvm/src/lib/penvm/lib/connection.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
__init__(host, port, sslcontext=None, sock=None)
Setup.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
Host address. |
required |
port |
int
|
Port. |
required |
sslcontext |
Union[SSLContext, None]
|
SSL context used for wrapping a regular socket to provide encryption. |
None
|
sock |
Union[socket, None]
|
Network socket. |
None
|
Source code in penvm/src/lib/penvm/lib/connection.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 |
|
recvmsg()
Receive message and return (as generic Message).
Returns:
Type | Description |
---|---|
Message
|
Received message. |
Source code in penvm/src/lib/penvm/lib/connection.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
sendmsg(msg)
Send message (serialized).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
Message
|
Message to send. |
required |
Source code in penvm/src/lib/penvm/lib/connection.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
ServerConnection
Bases: Connection
Server-side message queue connection.
Returned by Listener.
Source code in penvm/src/lib/penvm/lib/connection.py
639 640 641 642 643 644 645 646 647 648 649 650 |
|
__init__(*args, **kwargs)
Initialize.
Source code in penvm/src/lib/penvm/lib/connection.py
644 645 646 647 648 649 650 |
|
SocketConnection
Bases: BaseObject
Socket connection.
Provides the interface to the socket.
Source code in penvm/src/lib/penvm/lib/connection.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
|
__init__(host, port, sslcontext=None, sock=None)
Setup.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
Host address. |
required |
port |
int
|
Port. |
required |
sslcontext |
Union[SSLContext, None]
|
SSL context used for wrapping a regular socket to provide encryption. |
None
|
sock |
Union[socket, None]
|
Network socket. |
None
|
Source code in penvm/src/lib/penvm/lib/connection.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
|
close()
Close connection.
Source code in penvm/src/lib/penvm/lib/connection.py
337 338 339 340 341 |
|
connect()
Connection to server.
Source code in penvm/src/lib/penvm/lib/connection.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
is_alive()
Indicate if connection is alive or not.
Returns:
Type | Description |
---|---|
bool
|
Alive status. |
Source code in penvm/src/lib/penvm/lib/connection.py
343 344 345 346 347 348 349 |
|
is_connected()
Indicate if connected or not.
Returns:
Type | Description |
---|---|
bool
|
Connection status. |
Source code in penvm/src/lib/penvm/lib/connection.py
351 352 353 354 355 356 357 |
|
recv(sz)
Receive (all) bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sz |
int
|
Number of bytes. |
required |
Returns:
Type | Description |
---|---|
bytes
|
Bytes received. |
Source code in penvm/src/lib/penvm/lib/connection.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
recvblk(blkszlen=BLK_SZ_LEN)
Receive and return a block.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blkszlen |
int
|
Maximum receivable block size. |
BLK_SZ_LEN
|
Returns:
Type | Description |
---|---|
bytes
|
Bytes received. |
Source code in penvm/src/lib/penvm/lib/connection.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
send(b)
Send bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b |
bytes
|
Bytes to send. |
required |
Source code in penvm/src/lib/penvm/lib/connection.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
sendblk(b, blkszmax=BLK_SZ_MAX, blkszfmt=BLK_SZ_FMT)
Send a block (as bytes).
Size information is sent over the stream before the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b |
bytes
|
Bytes to send. |
required |
blkszmax |
int
|
Maximum sendable block size. |
BLK_SZ_MAX
|
blkszfmt |
int
|
Block size field format. |
BLK_SZ_FMT
|
Source code in penvm/src/lib/penvm/lib/connection.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
xsend(b)
Send all bytes.
Source code in penvm/src/lib/penvm/lib/connection.py
273 274 275 276 277 278 |
|
penvm.lib.connectionmanager
ConnectionManager
Bases: BaseObject
Manage connections set up by Listener.
- Listen for new connections (running in a thread).
- Spawn accepted connections (
Connection
runs its own threads).
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
__init__(machine, host, port, sslcontext=None)
Set up.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
machine |
Machine
|
Machine owning this manager. |
required |
host |
str
|
Host address to listen on. 0.0.0.0 for all interfaces. |
required |
port |
int
|
Port to listen on. 0 for auto assign. |
required |
sslcontext |
Union[SSLContext, None]
|
SSL context for SSL encrypted connections. |
None
|
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
drop(connectionid)
Drop connection by connection id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connectionid |
str
|
Connection id. |
required |
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
78 79 80 81 82 83 84 85 86 87 88 |
|
get(connectionid)
Get connection by connection id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connectionid |
str
|
Connection id. |
required |
Returns:
Type | Description |
---|---|
Connection
|
Connection for connection id. |
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
list()
Get list of connection ids.
Returns:
Type | Description |
---|---|
List[str]
|
Connection ids. |
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
104 105 106 107 108 109 110 |
|
run()
Run.
Listen for connections and add.
The initial connection must occur within a short amount of time (first-wait) and remain up for the lifetime of the machine. Once the initial connection drops, all others are dropped and the machine will end up shutting down.
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
shutdown(connectionid)
Force termination.
Intended to be called by Connection.onclose
instead of
ConnectionManager.drop()
when the initial connection
(init_conn
) is closed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connectionid |
str
|
Connection id. |
required |
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
start()
Start.
Background thread to handle connections.
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
state()
Get object state.
Returns:
Type | Description |
---|---|
State
|
|
Source code in penvm/src/lib/penvm/lib/connectionmanager.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
penvm.lib.debug
Debugging tools.
DataDumper
Dumps data to a destination (e.g., file) with support for serialization.
Source code in penvm/src/lib/penvm/lib/debug.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
__init__(path)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
File path to dump data. |
required |
Source code in penvm/src/lib/penvm/lib/debug.py
30 31 32 33 34 35 36 37 38 |
|
writebytes(b, flush=True)
Write bytes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b |
bytes
|
Bytes to write |
required |
flush |
bool
|
Flush stream. |
True
|
Source code in penvm/src/lib/penvm/lib/debug.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
writetext(t, flush=False)
Write text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
str
|
String to write. |
required |
flush |
bool
|
Flush to stream. |
False
|
Source code in penvm/src/lib/penvm/lib/debug.py
67 68 69 70 71 72 73 74 |
|
penvm.lib.kvstore
FInfo
File info for penvm.lib.kvstore.FileKVStore.
Tracks value type (text, bytes).
Source code in penvm/src/lib/penvm/lib/kvstore.py
177 178 179 180 181 182 183 184 185 |
|
__init__()
Initialize.
Source code in penvm/src/lib/penvm/lib/kvstore.py
183 184 185 |
|
FileKVStore
Bases: KVStore
File based penvm.lib.kvstore.KVStore.
Source code in penvm/src/lib/penvm/lib/kvstore.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
__init__(dirpath)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dirpath |
str
|
Directory path to store files. |
required |
See See penvm.lib.kvstore.KVStore.init.
Source code in penvm/src/lib/penvm/lib/kvstore.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
get(k, default=None)
See penvm.lib.kvstore.KVStore.get.
Source code in penvm/src/lib/penvm/lib/kvstore.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
|
get_path(k, default=None)
Return the path associated with the key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
str
|
Key. |
required |
default |
Union[str, None]
|
Default value. |
None
|
Returns:
Type | Description |
---|---|
str
|
File path holding value. |
Source code in penvm/src/lib/penvm/lib/kvstore.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
keys(pattern=None)
See penvm.lib.kvstore.KVStore.keys.
Source code in penvm/src/lib/penvm/lib/kvstore.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
pop(k)
See penvm.lib.kvstore.KVStore.pop.
Source code in penvm/src/lib/penvm/lib/kvstore.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
put(k, v)
See penvm.lib.kvstore.KVStore.put.
Source code in penvm/src/lib/penvm/lib/kvstore.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
|
KVStore
Bases: BaseObject
Base key+value store.
Source code in penvm/src/lib/penvm/lib/kvstore.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
__init__()
Initialize.
Source code in penvm/src/lib/penvm/lib/kvstore.py
35 36 37 |
|
drop(k)
Drop value for k.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
Any
|
Key. |
required |
Source code in penvm/src/lib/penvm/lib/kvstore.py
39 40 41 42 43 44 45 46 47 48 |
|
exists(k)
Indicate if key exists or not.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
Any
|
Key. |
required |
Returns:
Type | Description |
---|---|
bool
|
Status of k in store. |
Source code in penvm/src/lib/penvm/lib/kvstore.py
50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
get(k, default=None)
Get value for k.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
Any
|
Any. |
required |
default |
Any
|
Any. |
None
|
Returns:
Type | Description |
---|---|
Any
|
Value for k. |
Source code in penvm/src/lib/penvm/lib/kvstore.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
keys(pattern=None)
List of keys in store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pattern |
Union[str, None]
|
Filter for keys to return. |
None
|
Returns:
Type | Description |
---|---|
List[Any]
|
Keys matching pattern. |
Source code in penvm/src/lib/penvm/lib/kvstore.py
80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
pop(k, default=None)
Pop value from store for k.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
Any
|
Key. |
required |
Returns:
Type | Description |
---|---|
Any
|
Value for k or |
Source code in penvm/src/lib/penvm/lib/kvstore.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
put(k, v)
Put value in store.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
k |
Any
|
Key. |
required |
v |
Any
|
Value. |
required |
Source code in penvm/src/lib/penvm/lib/kvstore.py
109 110 111 112 113 114 115 116 117 118 119 120 |
|
state()
Get object state.
Returns:
Type | Description |
---|---|
State
|
|
Source code in penvm/src/lib/penvm/lib/kvstore.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
MemoryKVStore
Bases: KVStore
Memory based penvm.lib.kvstore.KVStore.
Source code in penvm/src/lib/penvm/lib/kvstore.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
__init__()
Initialize.
Source code in penvm/src/lib/penvm/lib/kvstore.py
143 144 145 146 147 |
|
exists(k)
See penvm.lib.kvstore.KVStore.exists.
Source code in penvm/src/lib/penvm/lib/kvstore.py
149 150 151 |
|
get(k, default=None)
See penvm.lib.kvstore.KVStore.get.
Source code in penvm/src/lib/penvm/lib/kvstore.py
153 154 155 156 157 158 159 |
|
keys(pattern=None)
See See penvm.lib.kvstore.KVStore.keys.
Source code in penvm/src/lib/penvm/lib/kvstore.py
161 162 163 164 165 166 |
|
pop(k)
See penvm.lib.kvstore.KVStore.pop.
Source code in penvm/src/lib/penvm/lib/kvstore.py
168 169 170 |
|
put(k, v)
See penvm.lib.kvstore.KVStore.put.
Source code in penvm/src/lib/penvm/lib/kvstore.py
172 173 174 |
|
penvm.lib.message
Header
Bases: MessagePart
Header.
Source code in penvm/src/lib/penvm/lib/message.py
267 268 269 270 271 272 273 274 275 276 277 278 |
|
__init__(d=None)
Initialize.
See penvm.lib.message.MessagePart.
Source code in penvm/src/lib/penvm/lib/message.py
270 271 272 273 274 275 276 277 278 |
|
JSONEncoder
Bases: json.JSONEncoder
Enhanced JSONEncoder with support for non-conforming types:
bytes
- Bytes.complex
- Complex.numpy.*
- Python-only.
Source code in penvm/src/lib/penvm/lib/message.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
Message
Object consisting of header and payload objects.
The header and payload objects are MessagePart
objects.
All parts have a -id
setting unique to the object.
Message payloads take special fields with -
prefix:
-type
- Message type (e.g., request, response)-status
- Status (e.g., ok, error)-message
- Status message, usually for "error" status.
Source code in penvm/src/lib/penvm/lib/message.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
__init__(header=None, payload=None)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
header |
Union[Header, None]
|
Header object. |
None
|
payload |
Union[Payload, None]
|
Payload object. |
None
|
Source code in penvm/src/lib/penvm/lib/message.py
309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
decode(b)
staticmethod
Decode bytes according to Message format.
Bytes as:
- header[HEADER_SZ_LEN] -> sz (encoded as plain text number)
- header[HEADER_SZ_LEN:HEADER_SZ_LEN+sz] -> bytes
- payload[PAYLOAD_SZ_LEN] -> sz (encoded as plain text number)
- payload[PAYLOAD_SZ_LEN:PAYLOAD_SZ_LEN+sz] -> bytes
See penvm.lib.message.MessagePart.
Source code in penvm/src/lib/penvm/lib/message.py
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
encode()
Encode.
Source code in penvm/src/lib/penvm/lib/message.py
354 355 356 357 358 |
|
state()
Get object state.
Returns:
Type | Description |
---|---|
State
|
|
Source code in penvm/src/lib/penvm/lib/message.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
MessagePart
Bases: MutableMapping
Dict-type object with enhanced json codec support for bytes.
Source code in penvm/src/lib/penvm/lib/message.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
__init__(d=None)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d |
dict
|
Initial configuration. |
None
|
Source code in penvm/src/lib/penvm/lib/message.py
134 135 136 137 138 139 140 141 142 143 144 145 |
|
decode(b)
staticmethod
Decode bytes with support for local decodings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b |
bytes
|
Bytes to decode. |
required |
Returns:
Type | Description |
---|---|
str
|
JSON string. |
Source code in penvm/src/lib/penvm/lib/message.py
172 173 174 175 176 177 178 179 180 181 182 |
|
dict(clean=False)
Return a copy as a dict. Optionally clean of "private" top-level items (keys start with "-").
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clean |
bool
|
Remove keys starting with "-". |
False
|
Returns:
Type | Description |
---|---|
Dict
|
Dictionary. |
Source code in penvm/src/lib/penvm/lib/message.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
dumps(indent=None, sort_keys=None)
Dump contents as a stringified dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent |
Union[int, None]
|
Indent size. |
None
|
sort_keys |
Union[bool, None]
|
Sort keys. |
None
|
Returns:
Type | Description |
---|---|
str
|
Stringified dictionary. |
Source code in penvm/src/lib/penvm/lib/message.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
encode()
Encode items and return JSON string.
Returns:
Type | Description |
---|---|
str
|
JSON string. |
Source code in penvm/src/lib/penvm/lib/message.py
226 227 228 229 230 231 232 |
|
json(indent=2, clean=False)
Return JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent |
Union[int, None]
|
Indent size. |
2
|
clean |
bool
|
Remove for keys starting with "-". |
False
|
Returns:
Type | Description |
---|---|
str
|
JSON string. |
Source code in penvm/src/lib/penvm/lib/message.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
yaml(clean=False)
Return YAML.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
clean |
bool
|
Remove for keys starting with "-". |
False
|
Returns:
Type | Description |
---|---|
str
|
YAML. |
Source code in penvm/src/lib/penvm/lib/message.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
Payload
Bases: MessagePart
Payload.
Source code in penvm/src/lib/penvm/lib/message.py
281 282 283 284 285 286 287 288 289 290 291 292 |
|
__init__(d=None)
Initialize.
See penvm.lib.message.MessagePart.
Source code in penvm/src/lib/penvm/lib/message.py
284 285 286 287 288 289 290 291 292 |
|
ErrorResponse(message, *args, **kwargs)
Return an error response message.
See penvm.lib.message.Message.
Source code in penvm/src/lib/penvm/lib/message.py
407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
OkResponse(*args, **kwargs)
Return an ok response message.
See penvm.lib.message.Message.
Source code in penvm/src/lib/penvm/lib/message.py
422 423 424 425 426 427 428 429 |
|
Request(*args, **kwargs)
Return a request message.
See penvm.lib.message.Message.
Source code in penvm/src/lib/penvm/lib/message.py
384 385 386 387 388 389 390 391 |
|
Response(*args, **kwargs)
Return a response message.
See penvm.lib.message.Message.
Source code in penvm/src/lib/penvm/lib/message.py
394 395 396 397 398 399 400 401 402 403 404 |
|
json_decoder_object_hook(o)
Support for decoding of non-conforming types:
bytes
- Bytes.complex
- Complex.numpy.*
- Numpy serialized objects (Python-only).
The encoding is an object as:
NON_CONFORMING: {
"type": <str>,
"value": <base64encoding>,
}
Note: Object keys cannot be bytes.
Source code in penvm/src/lib/penvm/lib/message.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
penvm.lib.misc
Collection of miscellaneous code.
LogMark
Provides unique id and time information: t0 (start time) and tlast (lap time).
Source code in penvm/src/lib/penvm/lib/misc.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
__init__()
Initialize.
Source code in penvm/src/lib/penvm/lib/misc.py
42 43 44 45 46 |
|
elapsed()
Return elapsed time since object initialize.
Returns:
Type | Description |
---|---|
float
|
Elapsed time in seconds. |
Source code in penvm/src/lib/penvm/lib/misc.py
48 49 50 51 52 53 54 55 |
|
lap()
Return triple (now, elasped since init, elapsed since last lap).
Returns:
Type | Description |
---|---|
float
|
Tuple of (not, elapsed since init, elapsed since lap) in |
float
|
seconds. |
Source code in penvm/src/lib/penvm/lib/misc.py
57 58 59 60 61 62 63 64 65 66 67 |
|
reset()
Reset the "init" time.
Source code in penvm/src/lib/penvm/lib/misc.py
69 70 71 |
|
LoggerAdapter
Bases: _LoggerAdapter
Log adapter which provides "owner" information as a prefix in the log entry.
Source code in penvm/src/lib/penvm/lib/misc.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
__init__(*args, **kwargs)
Initialize.
Source code in penvm/src/lib/penvm/lib/misc.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
enter(*args, **kwargs)
Set up a TaggedLoggerAdapter, call enter(), return new adapter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
List
|
Log message args. |
()
|
kwargs |
Dict
|
Log message kwargs. |
{}
|
Returns:
Type | Description |
---|---|
TaggedLoggerAdapter
|
TaggedLoggerAdapter. |
Source code in penvm/src/lib/penvm/lib/misc.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
process(msg, kwargs)
Return processed log message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
str
|
Message format string. |
required |
kwargs |
dict
|
Dictionary containers items for populating `msg. |
required |
Return
Processed message format string.
Source code in penvm/src/lib/penvm/lib/misc.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
MachineConnectionSpec
Machine connection spec.
Information required to establish a connection to a machine.
Source code in penvm/src/lib/penvm/lib/misc.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
__init__(machconnstr=None, config=None, machine=None)
Initialize.
One of the arguments is used to configure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
machconnstr |
Union[str, None]
|
Machine connection string: colon-separated string consisting of machine id, ssl profile, host, port. |
None
|
config |
Union[dict, None]
|
Dictionary of machine configuration settings. |
None
|
machine |
Union[Machine, None]
|
Machine object. |
None
|
Source code in penvm/src/lib/penvm/lib/misc.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
State
Bases: dict
Object state.
Holds object identifying information and a dictionary containing relevant object state.
Source code in penvm/src/lib/penvm/lib/misc.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
__init__(otype, oid, state)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
otype |
str
|
Object type string. |
required |
oid |
str
|
Object id string. |
required |
state |
dict
|
State information. |
required |
Source code in penvm/src/lib/penvm/lib/misc.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
TaggedLoggerAdapter
Bases: _LoggerAdapter
Logger adapter which tags each log entry with a unique id to allow for tracking. Also provides a means to track timing performance.
Also provides special methods for local (e.g., function/method) logger: enter, exit, elapsed, lap.
Source code in penvm/src/lib/penvm/lib/misc.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
__init__(*args, **kwargs)
Initialize.
Source code in penvm/src/lib/penvm/lib/misc.py
214 215 216 217 218 219 |
|
critical(msg, *args, **kwargs)
Make a "critical" log entry.
Source code in penvm/src/lib/penvm/lib/misc.py
221 222 223 224 |
|
debug(msg, *args, **kwargs)
Make a "debug" log entry.
Source code in penvm/src/lib/penvm/lib/misc.py
226 227 228 229 |
|
elapsed(msg=None)
Make a log entry with special format string containing: "ELAPSED", a tag, time, and elapsed time (from start).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
Union[str, None]
|
Additional message to log. |
None
|
Source code in penvm/src/lib/penvm/lib/misc.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
enter(msg=None, stacklevel=None)
Make a log entry with special format string containing: "ENTER", tag, and time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
Union[str, None]
|
Additional message to log. |
None
|
stacklevel |
Union[int, None]
|
Stack level to extract information from. |
None
|
Source code in penvm/src/lib/penvm/lib/misc.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
error(msg, *args, **kwargs)
Mark an "error" log entry.
Source code in penvm/src/lib/penvm/lib/misc.py
266 267 268 269 |
|
exit(msg=None)
Make a log entry with special format string containing: "EXIT", tag, time, and elapsed (from start).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
Union[str, None]
|
Additional message to log. |
None
|
Source code in penvm/src/lib/penvm/lib/misc.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
lap(msg=None)
Make a log entry with special format string containing: "LAP", tag, time, and elapsed from split, and from lap split.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg |
Union[str, None]
|
Additional message to log. |
None
|
Source code in penvm/src/lib/penvm/lib/misc.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
warning(msg, *args, **kwargs)
Make a "warning" log entry.
Source code in penvm/src/lib/penvm/lib/misc.py
312 313 314 315 |
|
get_log_mark()
Get log mark of (now, uuid).
Source code in penvm/src/lib/penvm/lib/misc.py
344 345 346 |
|
get_log_uuid()
Return UUID for logging.
Returns:
Type | Description |
---|---|
str
|
UUID string value. |
Source code in penvm/src/lib/penvm/lib/misc.py
323 324 325 326 327 328 329 330 331 332 |
|
get_log_uuid1()
Return UUID1 log logging.
Returns:
Type | Description |
---|---|
str
|
UUID1 string value. |
Source code in penvm/src/lib/penvm/lib/misc.py
335 336 337 338 339 340 341 |
|
get_timestamp()
Get timestamp as string.
Source code in penvm/src/lib/penvm/lib/misc.py
349 350 351 |
|
get_uuid()
Alternate get_uuid
implementation.
Source code in penvm/src/lib/penvm/lib/misc.py
358 359 360 361 362 363 |
|
get_uuid1()
Get UUID1 value.
Returns:
Type | Description |
---|---|
str
|
UUID1 string value. |
Source code in penvm/src/lib/penvm/lib/misc.py
366 367 368 369 370 371 372 373 |
|
get_version()
Return PENVM version tuple.
Returns:
Type | Description |
---|---|
Tuple
|
Version tuple. |
Source code in penvm/src/lib/penvm/lib/misc.py
377 378 379 380 381 382 |
|
get_version_string()
Return PENVM version as a string.
Returns:
Type | Description |
---|---|
str
|
Version string. |
Source code in penvm/src/lib/penvm/lib/misc.py
385 386 387 388 389 390 391 |
|
penvm.lib.mqueue
MessageQueue
Bases: BaseObject
, Queue
Message queue.
Built on top of penvm.lib.queue.Queue.
Source code in penvm/src/lib/penvm/lib/mqueue.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
__init__(qsize=0)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qsize |
int
|
Maximum queue size. 0 for unlimited. |
0
|
Source code in penvm/src/lib/penvm/lib/mqueue.py
39 40 41 42 43 44 45 46 |
|
find(id)
Find and return message in queue with given header id.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id |
str
|
Message header id. |
required |
Returns:
Type | Description |
---|---|
Message
|
Matching Message. |
Source code in penvm/src/lib/penvm/lib/mqueue.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
state()
Get object state.
Returns:
Type | Description |
---|---|
State
|
|
Source code in penvm/src/lib/penvm/lib/mqueue.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
penvm.lib.queue
Queue
Implementation allowing for inspection and peeking.
Built on top of [queue.Queue][].
Source code in penvm/src/lib/penvm/lib/queue.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
__init__(qsize=0)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
qsize |
int
|
Maximum queue size. 0 for unlimited. |
0
|
Source code in penvm/src/lib/penvm/lib/queue.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
clear()
Clear all queued objects.
Source code in penvm/src/lib/penvm/lib/queue.py
52 53 54 55 56 57 58 59 60 |
|
freeze(state)
Allow/disallow additions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
bool
|
New state of queue. |
required |
Source code in penvm/src/lib/penvm/lib/queue.py
62 63 64 65 66 67 68 69 70 71 |
|
get()
Get copy of object from queue.
Returns:
Type | Description |
---|---|
Any
|
Item. |
Source code in penvm/src/lib/penvm/lib/queue.py
73 74 75 76 77 78 79 80 81 82 |
|
pop(block=True)
Pop object from queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block |
bool
|
Wait for object. |
True
|
Returns:
Type | Description |
---|---|
Any
|
Item. |
Source code in penvm/src/lib/penvm/lib/queue.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
put(o)
Put object on queue.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
o |
Any
|
Object. |
required |
Source code in penvm/src/lib/penvm/lib/queue.py
104 105 106 107 108 109 110 111 112 |
|
size()
Return queue size.
Returns:
Type | Description |
---|---|
int
|
Queue size. |
Source code in penvm/src/lib/penvm/lib/queue.py
115 116 117 118 119 120 121 |
|
values()
Return (actual) queued values.
Returns:
Type | Description |
---|---|
List[Any]
|
Queue values. |
Source code in penvm/src/lib/penvm/lib/queue.py
123 124 125 126 127 128 129 |
|
RoutingQueue
Bases: Queue
Route queue operations elsewhere.
Three functions are registered to handle the different kinds of queueing (and this routing) operations.
Source code in penvm/src/lib/penvm/lib/queue.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
__init__(get=None, pop=None, put=None)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
get |
Union[Callable, None]
|
Function to call for |
None
|
pop |
Union[Callable, None]
|
Function to call for |
None
|
put |
Union[Callable, None]
|
Function to call for |
None
|
Source code in penvm/src/lib/penvm/lib/queue.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
get()
Get a copy of an object.
Returns:
Type | Description |
---|---|
Union[Any, None]
|
Copy of an object. |
Source code in penvm/src/lib/penvm/lib/queue.py
157 158 159 160 161 162 163 |
|
pop(block=True)
Pop an object.
Returns:
Type | Description |
---|---|
Union[Any, None]
|
An object. |
Source code in penvm/src/lib/penvm/lib/queue.py
165 166 167 168 169 170 171 172 173 174 |
|
put(o)
Put an object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
o |
Any
|
Object to queue/route. |
required |
Source code in penvm/src/lib/penvm/lib/queue.py
176 177 178 179 180 181 182 183 184 185 |
|
size()
Queue size is always 0.
Returns:
Type | Description |
---|---|
int
|
0 |
Source code in penvm/src/lib/penvm/lib/queue.py
187 188 189 190 191 192 193 |
|
values()
Never any values on queue.
Returns:
Type | Description |
---|---|
List
|
Empty list. |
Source code in penvm/src/lib/penvm/lib/queue.py
195 196 197 198 199 200 |
|
penvm.lib.semaphore
AdjustableSemaphore
Semaphore with support for adjusting the limit n
while in
use.
Source code in penvm/src/lib/penvm/lib/semaphore.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
__init__(n=1)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
Count. |
1
|
Source code in penvm/src/lib/penvm/lib/semaphore.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
acquire()
Acquire a semaphore.
Increase current count.
Source code in penvm/src/lib/penvm/lib/semaphore.py
49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
adjust(n=1)
Adjust count.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
New count. |
1
|
Source code in penvm/src/lib/penvm/lib/semaphore.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
count()
Return current count.
Returns:
Type | Description |
---|---|
int
|
Current count. |
Source code in penvm/src/lib/penvm/lib/semaphore.py
80 81 82 83 84 85 86 |
|
max()
Return maximum count allowed.
Returns:
Type | Description |
---|---|
int
|
Maximum count. |
Source code in penvm/src/lib/penvm/lib/semaphore.py
88 89 90 91 92 93 94 |
|
release()
Release a semaphore.
Decreases current count.
Source code in penvm/src/lib/penvm/lib/semaphore.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
penvm.lib.thread
Provides modified Thread
to support thread termination.
Thread
Bases: BaseObject
, threading.Thread
Thread with specific settings and functionality: * Will die on main thread exit. * Support for exception to thread. * Terminatable.
See https://code.activestate.com/recipes/496960-thread2-killable-threads/.
Source code in penvm/src/lib/penvm/lib/thread.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
__init__(*args, **kwargs)
Initialize.
See [theading.Thread][].
Source code in penvm/src/lib/penvm/lib/thread.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
get_id()
Return thread id.
Returns:
Type | Description |
---|---|
int
|
Thread id. |
Source code in penvm/src/lib/penvm/lib/thread.py
70 71 72 73 74 75 76 77 78 79 80 81 |
|
raise_exception(exc)
Raise a specific exception.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc |
Exception
|
Exception to raise. |
required |
Source code in penvm/src/lib/penvm/lib/thread.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
state()
Get object state.
Returns:
Type | Description |
---|---|
State
|
|
Source code in penvm/src/lib/penvm/lib/thread.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
terminate()
Terminate. Raises exception.
Source code in penvm/src/lib/penvm/lib/thread.py
128 129 130 131 132 133 |
|
ThreadInterrupt
Bases: Exception
Special exception for augmented Thread.
Source code in penvm/src/lib/penvm/lib/thread.py
34 35 36 37 38 39 |
|
__init__()
Initialize.
Source code in penvm/src/lib/penvm/lib/thread.py
37 38 39 |
|