Skip to main content

Threading and multiprocessing eye-candy.

Project description

Description

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

Examples

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})
thrd.join()

Most of the functions work as well as decorators:

from pebble import process

@process.spawn(daemon=True)
def function(foo, bar=0):
    print(foo + bar)

proc = function(1, bar=2)
proc.join()

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

from pebble import process

@process.concurrent
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" % (task.id,
                                                  results,
                                                  thread_id)

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.

Source Distribution

Pebble-3.1.14.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Pebble-3.1.14-py2.py3-none-any.whl (119.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file Pebble-3.1.14.tar.gz.

File metadata

  • Download URL: Pebble-3.1.14.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Pebble-3.1.14.tar.gz
Algorithm Hash digest
SHA256 0af4896b0d54bff35d606e59c6fc2df66bbaf92aa7bb7c092664e17379ee9015
MD5 bcc297a8a206d711cc9ec91eacc90eaa
BLAKE2b-256 2e7c2d8f7ed3aeb741ee3749114a80790bf84eb4da3156d1431a87757173621d

See more details on using hashes here.

File details

Details for the file Pebble-3.1.14-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for Pebble-3.1.14-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fe3fbef4dd6ea4cad9e286c0fadcf1bebb9edcfa34c55a778b7f0a14886e7ffa
MD5 69612c2569085966fe195f4dc040b4ed
BLAKE2b-256 d8f1dabd697334ad1b06aed637ce17cf04311d51124297418f36e08e2b4c8c95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page