Skip to content

Instantly share code, notes, and snippets.

@ringods
Created November 28, 2011 09:33
Show Gist options
  • Select an option

  • Save ringods/1399763 to your computer and use it in GitHub Desktop.

Select an option

Save ringods/1399763 to your computer and use it in GitHub Desktop.
rpyc workaround for async request and callback: sync request on separate thread
from threading import Thread
import rpyc
import logging
import time
class ClientWrapper(Thread):
def __init__(self):
Thread.__init__(self)
logging.info('client - before connect')
self._connection = rpyc.connect('127.0.0.1',39876)
logging.info('client - after connect')
logging.info('client - before retrieving method proxy')
self._sync_execute = self._connection.root.execute
logging.info('client - after retrieving method proxy')
def run(self):
logging.info('client - before sync exec')
self._sync_execute(self)
logging.info('client - after sync exec')
def stop(self):
logging.info('client - before Thread.join')
self.join()
logging.info('client - after Thread.join')
self._sync_execute = None
self._connection.close()
def exposed_callback(self):
logging.info('client - callback')
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format = '%(asctime)s - p=%(process)d - t=%(thread)d - %(name)s - %(levelname)s - %(message)s')
wrapper = ClientWrapper()
wrapper.start()
logging.info('client - before sleep 5 seconds')
time.sleep(5)
logging.info('client - after sleep 5 seconds')
wrapper.stop()
rdesmet@amplidata-desktop-ringo:~/Projects/amplidata/2.1/DSS-buchla-testsuite/test$ /opt/qbase3/bin/python client.py
2011-11-28 09:30:48,573 - p=18072 - t=139787142002416 - root - INFO - client - before connect
2011-11-28 09:30:48,576 - p=18072 - t=139787142002416 - root - INFO - client - after connect
2011-11-28 09:30:48,576 - p=17665 - t=140062707992304 - CUSTOM/39876 - INFO - accepted 127.0.0.1:60937
2011-11-28 09:30:48,576 - p=18072 - t=139787142002416 - root - INFO - client - before retrieving method proxy
2011-11-28 09:30:48,577 - p=18073 - t=140062707992304 - CUSTOM/39876 - INFO - welcome [127.0.0.1]:60937
2011-11-28 09:30:48,582 - p=18072 - t=139787142002416 - root - INFO - client - after retrieving method proxy
2011-11-28 09:30:48,583 - p=18072 - t=139787047885072 - root - INFO - client - before sync exec
2011-11-28 09:30:48,583 - p=18072 - t=139787142002416 - root - INFO - client - before sleep 5 seconds
2011-11-28 09:30:48,584 - p=18073 - t=140062707992304 - root - INFO - server - before sleep 10 seconds
2011-11-28 09:30:53,585 - p=18072 - t=139787142002416 - root - INFO - client - after sleep 5 seconds
2011-11-28 09:30:53,585 - p=18072 - t=139787142002416 - root - INFO - client - before Thread.join
2011-11-28 09:30:58,587 - p=18072 - t=139787047885072 - root - INFO - client - callback
2011-11-28 09:30:58,588 - p=18073 - t=140062707992304 - root - INFO - server - after sleep 10 seconds
2011-11-28 09:30:58,588 - p=18072 - t=139787047885072 - root - INFO - client - after sync exec
2011-11-28 09:30:58,589 - p=18072 - t=139787142002416 - root - INFO - client - after Thread.join
2011-11-28 09:30:58,589 - p=18073 - t=140062707992304 - CUSTOM/39876 - INFO - goodbye [127.0.0.1]:60937
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment