def __init__(self, address, thread=False): """ @param address (host,port) for the service @param thread If True, a thread is launched to call serve_forever on the simulator. Do not use this within a pyon-dominated environment because of gevent monkey patching behavior that doesn't play well with threading.Thread (you'll likely see the thread blocked). By default False. """ self._sim = CgsnSimulator(address) print("CgsnSimulatorServer listening on %s:%s ..." % (host, port)) if thread: self._check_pyon() from threading import Thread runnable = Thread(target=self._sim.serve_forever) runnable.start() print("started thread.") else: self._sim.serve_forever()
class CgsnSimulatorServer(object): """ CGSN simulator server """ def __init__(self, address, thread=False): """ @param address (host,port) for the service @param thread If True, a thread is launched to call serve_forever on the simulator. Do not use this within a pyon-dominated environment because of gevent monkey patching behavior that doesn't play well with threading.Thread (you'll likely see the thread blocked). By default False. """ self._sim = CgsnSimulator(address) print("CgsnSimulatorServer listening on %s:%s ..." % (host, port)) if thread: self._check_pyon() from threading import Thread runnable = Thread(target=self._sim.serve_forever) runnable.start() print("started thread.") else: self._sim.serve_forever() def shutdown(self): print("_sim.shutdown called.") if self._sim: self._sim.shutdown() self._sim = None @staticmethod def _check_pyon(): """ Prints a warning message if pyon is detected. """ import sys if "pyon" in sys.modules: m = "!! WARNING: pyon in sys.modules !!" s = "!" * len(m) sys.stderr.write("\n%s\n%s\n%s\n\n" % (s, m, s))
class CgsnSimulatorServer(object): """ CGSN simulator server """ def __init__(self, address, thread=False): """ @param address (host,port) for the service @param thread If True, a thread is launched to call serve_forever on the simulator. Do not use this within a pyon-dominated environment because of gevent monkey patching behavior that doesn't play well with threading.Thread (you'll likely see the thread blocked). By default False. """ self._sim = CgsnSimulator(address) print("CgsnSimulatorServer listening on %s:%s ..." % (host, port)) if thread: self._check_pyon() from threading import Thread runnable = Thread(target=self._sim.serve_forever) runnable.start() print("started thread.") else: self._sim.serve_forever() def shutdown(self): print("_sim.shutdown called.") if self._sim: self._sim.shutdown() self._sim = None @staticmethod def _check_pyon(): """ Prints a warning message if pyon is detected. """ import sys if 'pyon' in sys.modules: m = "!! WARNING: pyon in sys.modules !!" s = "!" * len(m) sys.stderr.write("\n%s\n%s\n%s\n\n" % (s, m, s))