def start(self, sleep=0, log=True, link=None, process=False): group = None target = self.run name = self.__class__.__name__ mode = "P" if process else "T" args = (sleep, log, mode) if process and HAS_MULTIPROCESSING: if link is not None and isinstance(link, Manager): from circuits.net.sockets import Pipe from circuits.core.bridge import Bridge from circuits.core.utils import findroot root = findroot(link) parent, child = Pipe() self._bridge = Bridge(root, socket=parent) self._bridge.start() args += (child,) self._task = Process(group, target, name, args) self._task.daemon = True if HAS_MULTIPROCESSING == 2: setattr(self._task, "isAlive", self._task.is_alive) self.tick() self._task.start() return self._task = Thread(group, target, name, args) self._task.setDaemon(True) self._task.start()
def register(self, parent): super(UPnPDeviceServer, self).register(parent) # SSDP transceiver, may exist only once if not any([isinstance(c, SSDPTranceiver) \ for c in flatten(findroot(self))]): SSDPTranceiver().register(self.parent) return self
def start(self, sleep=0, log=True, link=None, process=False): group = None target = self.run name = self.__class__.__name__ mode = "P" if process else "T" args = ( sleep, log, mode, ) if process and HAS_MULTIPROCESSING: if link is not None and isinstance(link, Manager): from circuits.net.sockets import Pipe from circuits.core.bridge import Bridge from circuits.core.utils import findroot root = findroot(link) parent, child = Pipe() self._bridge = Bridge(root, socket=parent) self._bridge.start() args += (child, ) self._task = Process(group, target, name, args) self._task.daemon = True if HAS_MULTIPROCESSING == 2: setattr(self._task, "isAlive", self._task.is_alive) self.tick() self._task.start() return self._task = Thread(group, target, name, args) self._task.setDaemon(True) self._task.start()
def test_findroot(): app = App() a = A() b = B() b.register(a) a.register(app) while app: app.flush() root = findroot(b) assert root == app