import time from Rpyc import SocketConnection, Async c = SocketConnection("localhost") c2 = SocketConnection("localhost") huge_xml = "<blah a='5' b='6'> " * 50000 + " </blah> " * 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)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os from gettext import gettext as _ #import logging from pydebug_logging import _logger, log_environment, log_dict #establish a remote procedure call pipe connection with the PyDebug process from Rpyc import SocketConnection try: c = SocketConnection('localhost') db = c.modules.pydebug.pydebug_instance #except AttributeError: # _logger.error('cannot connect to localhost') except Exception, e: _logger.exception('cannot connect to localhost') print 'Rpyc connection failed' print(str(e)) assert False pydebug_path = db.pydebug_path xmode = db.debug_dict.get('xmode') _logger.debug( './bin/start_debug.py established connectioon. pydebug path: %s' % pydebug_path) #these alternative definitions are required for ipython v0.11 and greater