def main(): global abort daemon = Pyro4.Daemon() server = Pyro4.Proxy("PYRONAME:example.deadlock") bounceObj = bouncer.Bouncer("Client") daemon.register(bounceObj) # callback object # register callback on the server server.register(bounceObj) # Now register server as 'callback' on the bounce object in this client # note: we're using the same proxy here as the main program! # This is the main cause of the deadlock, because this proxy will already # be engaged in a call when the callback object here wants to use it as well. # One solution could be to use a new proxy from inside the callback object, like this: # server2 = server.__copy__() # bounceObj.register(server2) bounceObj.register(server) # create a thread that handles callback requests thread = threading.Thread(target=PyroLoop, args=(daemon, )) thread.setDaemon(True) thread.start() print("This bounce example will deadlock!") print("Read the source or Readme.txt for more info why this is the case!") print("Calling server...") result = server.process(["hello"]) print( "Result=", result ) # <--- you will never see this, it will deadlock in the previous call
def main(): global abort Pyro.core.initServer() Pyro.core.initClient() daemon = Pyro.core.Daemon() NS = Pyro.naming.NameServerLocator().getNS() daemon.useNameServer(NS) bounceObj = bouncer.Bouncer("Client") daemon.connect(bounceObj) # callback object server = NS.resolve(':test.bouncer').getProxy() # create a thread that handles callback requests thread=Thread(target=PyroLoop, args=(daemon,)) thread.start() print 'Calling server from main (a single call)...' result = server.process(["hello"], bounceObj.getProxy()) print 'Result=',result abort=1 thread.join() print 'Exiting.'
from __future__ import print_function import Pyro4 import bouncer # you could set a comm timeout to avoid the deadlock situation...: # Pyro4.config.COMMTIMEOUT = 2 with Pyro4.Daemon() as daemon: uri = daemon.register(bouncer.Bouncer("Server")) Pyro4.locateNS().register("example.deadlock", uri) print("This bounce example will deadlock!") print("Read the source or Readme.txt for more info why this is the case!") print("Bouncer started.") daemon.requestLoop()
#!/usr/bin/env python import Pyro.naming import Pyro.core from Pyro.errors import NamingError import bouncer Pyro.core.initServer() daemon = Pyro.core.Daemon() ns = Pyro.naming.NameServerLocator().getNS() daemon.useNameServer(ns) try: ns.createGroup(':test') except NamingError: pass daemon.connect(bouncer.Bouncer('Server'),':test.bouncer') # enter the service loop. print 'Bouncer started' daemon.requestLoop()