2 from Rpyc.Factories import SocketConnection, Async
\r
4 c = SocketConnection("localhost")
\r
5 c2 = SocketConnection("localhost")
\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
11 print "while we're waiting for the server to complete, we do other stuff"
\r
13 while not res.is_ready:
\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
20 print "it took %d seconds" % (t,)
\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
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
38 # also, there's a memory leak on the server, which i'm working on solving.
\r