Process Timer
Installation
From source code:
python setup.py install
From pypi:
pip install process-timer
Usage
import time
from process_timer import timeout
@timeout(5)
def mytest():
print("Start")
for i in range(1,10):
time.sleep(1)
print(f"{i} seconds have passed")
if __name__ == '__main__':
mytest()
Specify an alternate exception to raise on timeout:
import time
from process_timer import timeout
@timeout(5, timeout_exception=StopIteration)
def mytest():
print("Start")
for i in range(1,10):
time.sleep(1)
print(f"{i} seconds have passed")
if __name__ == '__main__':
mytest()
Multithreading
By default, timeout-decorator uses signals to limit the execution time
of the given function. This appoach does not work if your function is
executed not in a main thread (for example if it's a worker thread of
the web application). There is alternative timeout strategy for this
case - by using multiprocessing. To use it, just pass
use_signals=False to the timeout decorator function:
import time
from process_timer import timeout
@timeout(5, use_signals=False)
def mytest():
print("Start")
for i in range(1,10):
time.sleep(1)
print(f"{i} seconds have passed")
if __name__ == '__main__':
mytest()
Warning Make sure that in case of multiprocessing strategy for timeout, your function does not return objects which cannot be pickled, otherwise it will fail at marshalling it between master and child processes.
Acknowledgement
- Timeout Decorator - https://github.com/pnpnpn/timeout-decorator
- http://www.saltycrane.com/blog/2010/04/using-python-timeout-decorator-uploading-s3/
- https://code.google.com/p/verse-quiz/source/browse/trunk/timeout.py
Contribute
I would love for you to fork and send me pull request for this project. Please contribute.
License
This software is licensed under the MIT license
See License file
Metadata
Release files for process-timer 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| process-timer-1.1.1.tar.gz | 4.4 kB | Without provenance | Details for process-timer-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| process_timer-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for process_timer-1.1.1-py3-none-any.whl |
Total release size: 10.0 kB
Release files / process-timer-1.1.1.tar.gz
| Download URL | process-timer-1.1.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f903e0a0c212ee4580f08fbd038323b1a925c9702df60f1fda918b573638c40f
|
|
BLAKE2b-256 checksum How to use checksums |
56b249371c8102ad77f1d3fcc38e69e44d746abcc0a87c20f2d785a513719119
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.8
|
Release files / process_timer-1.1.1-py3-none-any.whl
| Download URL | process_timer-1.1.1-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
24199f6a2cf61de93b24435f9aa1f408cb494165a67a77724441a0de51aef408
|
|
BLAKE2b-256 checksum How to use checksums |
dad4c68545e7cec06bad5141387212c067316845ab03cde23d66c41f41b42575
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.8
|
Security for process-timer 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.