Skip to main content

Threading and multiprocessing eye-candy.

Project description


Pebble provides a neat API to manage threads and processes within an application.


Spawn a function within a thread:

from pebble import thread

def function(foo, bar=0):
    print foo + bar

thrd = thread.spawn(target=function, args=[1], kwargs={'bar':2})

Most of the functions work as well as decorators:

from pebble import process

def function(foo, bar=0):
    print(foo + bar)

proc = function(1, bar=2)

Run a job in a separate process and wait for its results:

from pebble import process

def function(foo, bar=0):
    return foo + bar

task = function(1, bar=2)
results = task.get()  # blocks until results are ready

Pools allow to execute several tasks without the need of spawning a new worker for each one of them:

from threading import current_thread
from pebble import thread

def task_done(task):
    results, thread_id = task.get()
    print "Task %s returned %d from thread %s" % (,

def do_job(foo, bar=0):
    return foo + bar, current_thread().ident

with thread.Pool(workers=5) as pool:
    for i in range(0, 10):
        pool.schedule(do_job, args=(i, ), callback=task_done)

Check the documentation for more examples.

Pebble 4:

  • use Futures instead of Tasks
  • move callback and timeout assignments to Futures
  • merge with concurrent.futures and asyncio modules API

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.

Files for Pebble, version 3.1.17
Filename, size File type Python version Upload date Hashes
Filename, size Pebble-3.1.17-py2.py3-none-any.whl (49.2 kB) File type Wheel Python version 3.5 Upload date Hashes View
Filename, size Pebble-3.1.17.tar.gz (22.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page