asynctask1.py
32 lines
| 774 B
| text/x-python
|
PythonLexer
Brian E Granger
|
r1337 | #!/usr/bin/env python | ||
# encoding: utf-8 | ||||
# This example shows how the AsynTaskClient can be used | ||||
Brian E Granger
|
r1338 | # This example is currently broken | ||
Brian E Granger
|
r1337 | |||
from twisted.internet import reactor, defer | ||||
Brian E Granger
|
r1338 | from IPython.kernel import asyncclient | ||
Brian E Granger
|
r1337 | |||
Brian E Granger
|
r1338 | mec = asyncclient.AsyncMultiEngineClient(('localhost', 10105)) | ||
tc = asyncclient.AsyncTaskClient(('localhost',10113)) | ||||
Brian E Granger
|
r1337 | |||
cmd1 = """\ | ||||
a = 5 | ||||
b = 10*d | ||||
c = a*b*d | ||||
""" | ||||
Brian E Granger
|
r1338 | t1 = asyncclient.Task(cmd1, clear_before=False, clear_after=True, pull=['a','b','c']) | ||
Brian E Granger
|
r1337 | |||
d = mec.push(dict(d=30)) | ||||
def raise_and_print(tr): | ||||
tr.raiseException() | ||||
print "a, b: ", tr.ns.a, tr.ns.b | ||||
return tr | ||||
d.addCallback(lambda _: tc.run(t1)) | ||||
d.addCallback(lambda tid: tc.get_task_result(tid,block=True)) | ||||
d.addCallback(raise_and_print) | ||||
d.addCallback(lambda _: reactor.stop()) | ||||
reactor.run() | ||||