Skip to content

Instantly share code, notes, and snippets.

@ringods
Created November 25, 2011 10:24
Show Gist options
  • Save ringods/1393212 to your computer and use it in GitHub Desktop.
Save ringods/1393212 to your computer and use it in GitHub Desktop.
rpyc async request: faulty 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(self)
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:22:59,221 - 5462 - 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:23:02,946 - 5467 - root - INFO - client - before connect
2011-11-25 10:23:02,949 - 5467 - root - INFO - client - after connect
2011-11-25 10:23:02,949 - 5462 - CUSTOM/39876 - INFO - accepted 127.0.0.1:60519
2011-11-25 10:23:02,949 - 5467 - root - INFO - client - before retrieving async proxy
2011-11-25 10:23:02,950 - 5468 - CUSTOM/39876 - INFO - welcome [127.0.0.1]:60519
2011-11-25 10:23:02,956 - 5467 - root - INFO - client - after retrieving async proxy
2011-11-25 10:23:02,956 - 5467 - root - INFO - client - before async exec
2011-11-25 10:23:02,956 - 5467 - root - INFO - client - after async exec
2011-11-25 10:23:02,956 - 5467 - root - INFO - client - before sleep 5 seconds
2011-11-25 10:23:07,961 - 5467 - root - INFO - client - after sleep 5 seconds
2011-11-25 10:23:07,962 - 5467 - root - INFO - client - before AsyncResult.wait
2011-11-25 10:23:07,965 - 5468 - root - INFO - server - before sleep 10 seconds
2011-11-25 10:23:17,974 - 5467 - root - INFO - client - callback
2011-11-25 10:23:17,974 - 5468 - root - INFO - server - after sleep 10 seconds
2011-11-25 10:23:17,974 - 5467 - root - INFO - client - after AsyncResult.wait
2011-11-25 10:23:17,975 - 5468 - CUSTOM/39876 - INFO - goodbye [127.0.0.1]:60519
from rpyc.core.service import Service
from rpyc.utils.server import ForkingServer
import logging
import time
class CustomService(Service):
def exposed_execute(self, callBackObject):
logging.info('server - before sleep 10 seconds')
time.sleep(10)
callBackObject.callback()
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