Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow empty callbacks

  • Loading branch information...
commit 06c1d5743afd5f4eb6bede6a2cad19cbf4357a9d 1 parent 361d250
@kmike authored
View
2  slacker/postpone.py
@@ -87,7 +87,7 @@ def _proceed(self):
result = func(*op[1], **op[2])
return result
- def proceed(self, callback, worker=None):
+ def proceed(self, callback=None, worker=None):
"""
Executes the collected chain using given worker and calls the
callback with results.
View
7 slacker/workers/http.py
@@ -26,11 +26,12 @@ class HttpWorker(object):
def __init__(self, server='127.0.0.1:8000', path='/'):
self.url = server + path
- def proceed(self, postponed, callback):
+ def proceed(self, postponed, callback=None):
def on_response(response):
- result = pickle.loads(response.body)
- callback(result)
+ if callback:
+ result = pickle.loads(response.body)
+ callback(result)
http = self.HTTPClient()
http.fetch(self.url, on_response, method='POST', body=postponed._pickled)
View
11 slacker/workers/local.py
@@ -4,8 +4,10 @@
class DummyWorker(object):
""" Dummy worker for local immediate execution """
- def proceed(self, postponed, callback):
- callback(postponed._proceed())
+ def proceed(self, postponed, callback = None):
+ res = postponed._proceed()
+ if callback:
+ callback(res)
class ThreadWorker(object):
@@ -40,7 +42,10 @@ def __init__(self, pool=None, ioloop=None):
self.pool = pool or self.__class__._default_pool
- def proceed(self, postponed, callback):
+ def proceed(self, postponed, callback=None):
+ if callback is None:
+ self.pool.apply_async(postponed._proceed)
+ return
def on_response(result):
self.ioloop.add_callback(partial(callback, result))
Please sign in to comment.
Something went wrong with that request. Please try again.