X-Git-Url: http://git.onelab.eu/?p=monitor.git;a=blobdiff_plain;f=monitor%2FRpyc%2FDemo%2Fdemo-4.py;fp=monitor%2FRpyc%2FDemo%2Fdemo-4.py;h=1a651ae95e1e3cd401f9ce71cb97683db7085023;hp=0000000000000000000000000000000000000000;hb=334378a14103c3fd02332b6ce3767553f1fe11d2;hpb=486326759a86f1315d93aeaccf6e2641af2bd9d9 diff --git a/monitor/Rpyc/Demo/demo-4.py b/monitor/Rpyc/Demo/demo-4.py new file mode 100644 index 0000000..1a651ae --- /dev/null +++ b/monitor/Rpyc/Demo/demo-4.py @@ -0,0 +1,41 @@ +import time +from Rpyc.Factories import SocketConnection, Async + +c = SocketConnection("localhost") +c2 = SocketConnection("localhost") + +huge_xml = " " * 50000 + " " * 50000 +parseString = Async(c.modules.xml.dom.minidom.parseString) +res = parseString(huge_xml) + +print "while we're waiting for the server to complete, we do other stuff" +t = time.time() +while not res.is_ready: + time.sleep(0.5) + # we dont want to use `c`, because it would block us (as the server is blocking) + # but `c2` runs on another thread/process, so it wouldn't block + print c2.modules.os.getpid() + +t = time.time() - t +print "it took %d seconds" % (t,) + +print res.result + + +# +# note: to improve performance, delete the result when you no longer need it. +# this should be done because the server might (as in this case) hold enormous +# amounts of memory, which will slow it down +# +# if you do this: +# res = parseString(huge_xml) +# res = parseString(huge_xml) +# res will be deleted only after the second operation finishes, because only when +# the second result is assigned, the first is released -- server still holds +# around 160MB of the old xml tree for nothing. so it's a good idea to `del res` +# when you dont need it. +# +# also, there's a memory leak on the server, which i'm working on solving. +# + +