Skip to content

Instantly share code, notes, and snippets.

@progrium
Last active December 18, 2015 06:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save progrium/5737696 to your computer and use it in GitHub Desktop.
Save progrium/5737696 to your computer and use it in GitHub Desktop.
Plans to break out AsyncManager from Ginkgo as standalone project for standard interface / tools / conveniences when working with gevent, Eventlet, threading, or even multiprocessing.

Ginkgo Async

Extracted Async Manager from Ginkgo as standalone project. At the very least it provides a common interface / abstraction for Gevent and Eventlet, but also for multi-threading and multi-processing.

Using Ginkgo Async interface

# easy async global singleton object
from ginkgo.async import async

# initialization
async.init('gevent', patch=['socket'])

# spawn a new (green) thread
async.spawn(myfunc)

# schedule (green) thread to be spawned
async.spawn_later(5, myfunc)

# sleep and yield
async.sleep(1.0)

# semantic convenience for async.sleep(0)
async.yield()

# factory for common event primitive
event = async.event()

# factory for common basic lock primitive
lock = async.lock()

# factory for basic queue
queue = async.queue()

# signal handling
async.signal('SIGALRM', handler)

# close down (green) threads
async.shutdown()

Convenience

# wrap function call with async.spawn
@async.autospawn
def some_async_func():
    pass

Implementation details

Manages all created threads in a group.

Future

Could provide multiple async managers to provide ability to run multiple types of async engines at once. Could provide standard server/client classes/wrappers like Ginkgo considered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment