Skip to content

Instantly share code, notes, and snippets.

@rjosephwright
Last active December 20, 2015 05:19
Show Gist options
  • Select an option

  • Save rjosephwright/6077428 to your computer and use it in GitHub Desktop.

Select an option

Save rjosephwright/6077428 to your computer and use it in GitHub Desktop.
from functools import wraps
class Function(Task):
@staticmethod
def executor(qname):
queue = get_queue(qname)
while True:
task = queue.get()
func, args, kwargs = task.funcspec
task.put(func(*args, **kwargs))
def __init__(self, func, args, kwargs, qname):
self.funcspec = func, args, kwargs
Task.__init__(self, qname)
def atomic(qname):
def _atomic(func):
@wraps(func)
def wrapper(*args, **kwargs):
return Function(func, args, kwargs, qname).run().get()
return wrapper
return _atomic
@atomic('pointless')
def pointless():
print('Only one of me can run at a time!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment