report any expired sites & nodes
[monitor.git] / Rpyc / Demo / demo-4.py
1 import time\r
2 from Rpyc.Factories import SocketConnection, Async\r
3 \r
4 c = SocketConnection("localhost")\r
5 c2 = SocketConnection("localhost")\r
6 \r
7 huge_xml = "<blah a='5' b='6'>   " * 50000 + "   </blah> " * 50000\r
8 parseString = Async(c.modules.xml.dom.minidom.parseString)\r
9 res = parseString(huge_xml)\r
10 \r
11 print "while we're waiting for the server to complete, we do other stuff"\r
12 t = time.time()\r
13 while not res.is_ready:\r
14     time.sleep(0.5)\r
15     # we dont want to use `c`, because it would block us (as the server is blocking)\r
16     # but `c2` runs on another thread/process, so it wouldn't block\r
17     print c2.modules.os.getpid()\r
18 \r
19 t = time.time() - t\r
20 print "it took %d seconds" % (t,)\r
21 \r
22 print res.result\r
23 \r
24 \r
25 #\r
26 # note: to improve performance, delete the result when you no longer need it.\r
27 # this should be done because the server might (as in this case) hold enormous \r
28 # amounts of memory, which will slow it down\r
29 #\r
30 # if you do this:\r
31 #   res = parseString(huge_xml)\r
32 #   res = parseString(huge_xml)\r
33 # res will be deleted only after the second operation finishes, because only when\r
34 # the second result is assigned, the first is released -- server still holds \r
35 # around 160MB of the old xml tree for nothing. so it's a good idea to `del res` \r
36 # when you dont need it.\r
37 #\r
38 # also, there's a memory leak on the server, which i'm working on solving.\r
39 #\r
40 \r
41 \r