Thread-creation helper
The thread-creation API provided by the Python threading module is annoying. :)
This package provides a very simple thread-creation API that:
Makes threads daemonic and allows daemonicity to be passed to the constructor. For example:
zc.thread.Thread(mythreadfunc)
Starts a daemonic thread named 'mythreadfunc' running mythreadfunc.
Allows threads to be defined via decorators, as in:
import zc.thread @zc.thread.Thread def mythread(): ...In the example above, a daemonic thread named mythread is created and started. The thread is also assigned to the variable mythread.
You can control whether threads are daemonic and wether they are started by default:
import zc.thread @zc.thread.Thread(daemon=False, start=False) def mythread(): ...After a thread finishes, you can get the return value of the target function from the thread’s value attribute, or, if the function raises an exception, you can get the exception object from the thread’s exception attribute. (This feature was inspired by the same feature in gevent greenlets.)
If a thread raises an exception (subclass of Exception), the exception is logged and a traceback is printed to standard error.
A restart argument can be used to rerun a thread target function if there’s an uncaught exception. Value passed to the restart argument is passed to time.sleep before restarting the function.
There’s also a Process constructor/decorator that works like Thread, but with multi-processing processes, and without the value and exception attributes.
Changes
1.0.0 (2015-06-17)
Python 3 support
Thread names now include a function’s module name.
Unhandled exceptions in thread and process targets are now logged and printed with tracebacks.
A restart argument can be used to automatically restart thread targets after a rest.
0.1.0 (2011-11-27)
Initial release
Release files for zc.thread 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zc.thread-1.0.0.tar.gz | 4.7 kB | Details |
Release files / zc.thread-1.0.0.tar.gz
| Download URL | zc.thread-1.0.0.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
650c6c706ef96dec5ade98d01c070a2a87b94429ed366209fffd134620eec5f9
|
|
BLAKE2b-256 checksum How to use checksums |
9379b9f88cbb1dcb5d3bd2ff1b4a5eefe6ac5164181cd90e740bdea20364db91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |