Threading and multiprocessing eye-candy.
Project description
Pebble provides a neat API to manage threads and processes within an application.
Source: | https://github.com/noxdafox/pebble |
---|---|
Documentation: | https://pebble.readthedocs.io |
Download: | https://pypi.python.org/pypi/pebble |
Examples
Run a job in a separate thread and wait for its results.
from pebble import concurrent @concurrent.thread def function(foo, bar=0): return foo + bar future = function(1, bar=2) result = future.result() # blocks until results are ready
Run a function with a timeout of ten seconds and deal with errors.
from pebble import concurrent from concurrent.futures import TimeoutError @concurrent.process(timeout=10) def function(foo, bar=0): return foo + bar future = function(1, bar=2) try: result = future.result() # blocks until results are ready except TimeoutError as error: print("Function took longer than %d seconds" % error.args[1]) except Exception as error: print("Function raised %s" % error) print(error.traceback) # traceback of the function
Pools support workers restart, timeout for long running tasks and more.
from pebble import ProcessPool from concurrent.futures import TimeoutError def function(foo, bar=0): return foo + bar def task_done(future): try: result = future.result() # blocks until results are ready except TimeoutError as error: print("Function took longer than %d seconds" % error.args[1]) except Exception as error: print("Function raised %s" % error) print(error.traceback) # traceback of the function with ProcessPool(max_workers=5, max_tasks=10) as pool: for i in range(0, 10): future = pool.schedule(function, args=[i], timeout=3) future.add_done_callback(task_done)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size Pebble-4.6.0-py2.py3-none-any.whl (24.8 kB) | File type Wheel | Python version 3.7 | Upload date | Hashes View |
Filename, size Pebble-4.6.0.tar.gz (23.9 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for Pebble-4.6.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21e633241534e580d6cd01d45f725ad70e7a0749c26dd3433cb080f7f78f4ba0 |
|
MD5 | d8f9119080739f7f43b458ff2c93fe05 |
|
BLAKE2-256 | 5a05ca1446ede9a2fbb1ce49416f16aa57e3e5d13d1b55131232cd9f85bafe23 |