Threading and multiprocessing eye-candy.
Project description
Description
Pebble provides a neat API to manage threads and processes within an application.
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 @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 Exception as error: print("Function raised %s" % error) print(error.traceback) # traceback of the function except TimeoutError as error: print("Function took longer than %d seconds" % error.args[1])
Pools support workers restart, timeout for long running tasks and more:
from pebble import ProcessPool def function(foo, bar=0): return foo + bar def task_done(future): try: result = future.result() # blocks until results are ready except Exception as error: print("Function raised %s" % error) print(error.traceback) # traceback of the function except TimeoutError as error: print("Function took longer than %d seconds" % error.args[1]) 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.
Source Distribution
Pebble-4.2.0.tar.gz
(19.6 kB
view hashes)
Built Distribution
Pebble-4.2.0-py2.py3-none-any.whl
(20.7 kB
view hashes)
Close
Hashes for Pebble-4.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14132f9d427ec9f1d78afdf683aed7abb6b43f5800e2e9acc2a3c8b453763296 |
|
MD5 | 3eb9505e6a508a7ce1dd7a5104a81a7a |
|
BLAKE2b-256 | 053e6226645f7be97e3dfea9b27901e4d9b2fe0778262308ee91f4c389b11d44 |