Pebble
Pebble provides a neat API to manage threads and processes within an application.
- Source:
- Documentation:
- Download:
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)
Metadata
Release files for Pebble 4.4.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 | |
|---|---|---|---|
| Pebble-4.4.1.tar.gz | 23.5 kB | Details |
Release files / Pebble-4.4.1.tar.gz
| Download URL | Pebble-4.4.1.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7c4d68a3479140cba74d7454d8190e2cb1a93213b44b5befe3c53c201beb8317
|
|
BLAKE2b-256 checksum How to use checksums |
5ea316f98c868854a6916d68bb6ea02edcf7c91021ad41892862f1307c6831df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|