Asynchronous function calls using lovely.remotetask
Project description
gocept.async provides asynchronous function calls using a decorator. It facilitates lovely.remotetask to actually do things asynchronously.
Details
It is often desirable to process computations asynchronously. Until there was lovely.remotetask this was not so easy to achieve in a Zope 3 application due to transaction integration issues.
gocept.async makes the task even easier:
>>> import gocept.async >>> @gocept.async.function(service='events') ... def heavy_computing(a, b): ... print "Computing", a, "+", b, "=", a + b
The decorator gocept.async.function takes exactly one argument, the name of a lovely.remotetask.interfaces.ITaskService utility. Note that gocept.async does not define any task service by itself [2] [1] . When the decorated function is called it returns nothing:
>>> heavy_computing(2, 7)
When we start the processing of the task service, the function is called:
>>> gocept.async.tests.process() Computing 2 + 7 = 9
When the function is called while a user is logged in, the function will be called as that user[#proxy]_:
>>> @gocept.async.function('events') ... def who_am_i(): ... print gocept.async.task.TaskDescription.get_principal() ... >>> who_am_i.undecorated.__module__ = 'gocept.async.tests' >>> gocept.async.tests.who_am_i = who_am_i >>> who_am_i() >>> gocept.async.tests.process()
Now login:
>>> gocept.async.tests.login('zope.user') >>> who_am_i() >>> gocept.async.tests.process() zope.user >>> gocept.async.tests.logout()
Changes
0.2 (2009-04-16)
Made it even less likely that tests will raise ConflictErrors.
Fixed tests in README.
0.1.1 (2009-02-11)
Made it less likely that tests will raise ConflictErrors.
0.1 (2009-02-11)
first internal release.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.