Skip to content

Instantly share code, notes, and snippets.

@ringods
Created November 25, 2011 10:21
Show Gist options
  • Save ringods/1393209 to your computer and use it in GitHub Desktop.
Save ringods/1393209 to your computer and use it in GitHub Desktop.
rpyc async request: correct behaviour
import rpyc
import logging
import time
class ClientWrapper:
def __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 async proxy')
self._async_execute = rpyc.async(self._connection.root.execute)
logging.info('client - after retrieving async proxy')
self._async_result = None
def start(self):
logging.info('client - before async exec')
self._async_result = self._async_execute()
logging.info('client - after async exec')
def stop(self):
logging.info('client - before AsyncResult.wait')
self._async_result.wait()
logging.info('client - after AsyncResult.wait')
self._async_result = None
self._async_execute = None
self._connection.close()
def exposed_callback(self):
logging.info('client - callback')
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format = '%(asctime)s - %(process)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 service.py
2011-11-25 10:20:40,200 - 5243 - CUSTOM/39876 - INFO - server started on [0.0.0.0]:39876
^Z
[1]+ Stopped /opt/qbase3/bin/python service.py
rdesmet@amplidata-desktop-ringo:~/Projects/amplidata/2.1/DSS-buchla-testsuite/test$ bg
[1]+ /opt/qbase3/bin/python service.py &
rdesmet@amplidata-desktop-ringo:~/Projects/amplidata/2.1/DSS-buchla-testsuite/test$ /opt/qbase3/bin/python client.py
2011-11-25 10:20:44,776 - 5248 - root - INFO - client - before connect
2011-11-25 10:20:44,778 - 5248 - root - INFO - client - after connect
2011-11-25 10:20:44,778 - 5243 - CUSTOM/39876 - INFO - accepted 127.0.0.1:60511
2011-11-25 10:20:44,778 - 5248 - root - INFO - client - before retrieving async proxy
2011-11-25 10:20:44,780 - 5249 - CUSTOM/39876 - INFO - welcome [127.0.0.1]:60511
2011-11-25 10:20:44,786 - 5248 - root - INFO - client - after retrieving async proxy
2011-11-25 10:20:44,786 - 5248 - root - INFO - client - before async exec
2011-11-25 10:20:44,786 - 5248 - root - INFO - client - after async exec
2011-11-25 10:20:44,786 - 5248 - root - INFO - client - before sleep 5 seconds
2011-11-25 10:20:44,786 - 5249 - root - INFO - server - before sleep 10 seconds
2011-11-25 10:20:49,791 - 5248 - root - INFO - client - after sleep 5 seconds
2011-11-25 10:20:49,791 - 5248 - root - INFO - client - before AsyncResult.wait
2011-11-25 10:20:54,789 - 5249 - root - INFO - server - after sleep 10 seconds
2011-11-25 10:20:54,789 - 5248 - root - INFO - client - after AsyncResult.wait
2011-11-25 10:20:54,790 - 5249 - CUSTOM/39876 - INFO - goodbye [127.0.0.1]:60511
rdesmet@amplidata-desktop-ringo:~/Projects/amplidata/2.1/DSS-buchla-testsuite/test$
from rpyc.core.service import Service
from rpyc.utils.server import ForkingServer
import logging
import time
class CustomService(Service):
def exposed_execute(self):
logging.info('server - before sleep 10 seconds')
time.sleep(10)
logging.info('server - after sleep 10 seconds')
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format = '%(asctime)s - %(process)d - %(name)s - %(levelname)s - %(message)s')
server = ForkingServer(CustomService, port = 39876)
server.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment