def __init__(self, host=None, port=0, unixsocket=None, nathost=None, natport=None): _check_hmac() # check if hmac secret key is set if host is None: host = Pyro4.config.HOST if nathost is None: nathost = Pyro4.config.NATHOST if natport is None: natport = Pyro4.config.NATPORT or None if nathost and unixsocket: raise ValueError("cannot use nathost together with unixsocket") if (nathost is None) ^ (natport is None): raise ValueError("must provide natport with nathost") if Pyro4.config.SERVERTYPE == "thread": self.transportServer = SocketServer_Threadpool() elif Pyro4.config.SERVERTYPE == "multiplex": # choose the 'best' multiplexing implementation if os.name == "java": raise NotImplementedError( "select or poll-based server is not supported for jython, use thread server instead" ) self.transportServer = SocketServer_Poll( ) if socketutil.hasPoll else SocketServer_Select() else: raise errors.PyroError("invalid server type '%s'" % Pyro4.config.SERVERTYPE) self.transportServer.init(self, host, port, unixsocket) #: The location (str of the form ``host:portnumber``) on which the Daemon is listening self.locationStr = self.transportServer.locationStr log.debug("created daemon on %s", self.locationStr) natport_for_loc = natport if natport == 0: # expose internal port number as NAT port as well. (don't use port because it could be 0 and will be chosen by the OS) natport_for_loc = int(self.locationStr.split(":")[1]) #: The NAT-location (str of the form ``nathost:natportnumber``) on which the Daemon is exposed for use with NAT-routing self.natLocationStr = "%s:%d" % (nathost, natport_for_loc) if nathost else None if self.natLocationStr: log.debug("NAT address is %s", self.natLocationStr) pyroObject = DaemonObject(self) pyroObject._pyroId = constants.DAEMON_NAME #: Dictionary from Pyro object id to the actual Pyro object registered by this id self.objectsById = {pyroObject._pyroId: pyroObject} self.__mustshutdown = threadutil.Event() self.__loopstopped = threadutil.Event() self.__loopstopped.set() # assert that the configured serializers are available, and remember their ids: self.__serializer_ids = set([ util.get_serializer(ser_name).serializer_id for ser_name in Pyro4.config.SERIALIZERS_ACCEPTED ]) log.debug("accepted serializers: %s" % Pyro4.config.SERIALIZERS_ACCEPTED)
def testConnectingThreads(self): class ConnectingThread(threadutil.Thread): new_connections = threadutil.AtomicCounter() def __init__(self, proxy, event): threadutil.Thread.__init__(self) self.proxy = proxy self.event = event self.setDaemon(True) self.new_connections.reset() def run(self): self.event.wait() if self.proxy._pyroBind(): ConnectingThread.new_connections.incr() # 1 more new connection done with Pyro4.core.Proxy(self.objectUri) as proxy: event = threadutil.Event() threads = [ConnectingThread(proxy, event) for _ in range(20)] for t in threads: t.start() event.set() for t in threads: t.join() self.assertEqual(1, ConnectingThread.new_connections.value) # proxy shared among threads must still have only 1 connect done
def __init__(self, pyrodaemon): super(DaemonLoopThread, self).__init__() self.setDaemon(True) self.pyrodaemon = pyrodaemon self.running = threadutil.Event() self.running.clear()
def __init__(self, hostname): super(NameServer, self).__init__() self.setDaemon(1) self.hostname = hostname self.started = threadutil.Event()
def __init__(self, nameserver): super(NSLoopThread, self).__init__() self.setDaemon(True) self.nameserver = nameserver self.running = threadutil.Event() self.running.clear()
def __init__(self, server, daemon): threadutil.Thread.__init__(self) self.serv = server() self.serv.init(daemon(), "localhost", 0) self.locationStr = self.serv.locationStr self.stop_loop = threadutil.Event()
def __init__(self): self.__ready = threadutil.Event() self.callchain = [] self.valueLock = threadutil.Lock()
def __init__(self): self.__ready = threadutil.Event() self.callchain = [] self.valueLock = threadutil.Lock() self.exceptionhandler = None