def run_proxy(queue): """ Run Proxy on random, free ports and communicate the port numbers back. """ from bluesky.callbacks.zmq import Proxy proxy = Proxy() queue.put((proxy.in_port, proxy.out_port)) proxy.start()
def main(): DESC = "Start a 0MQ proxy for publishing bluesky documents over a network." parser = argparse.ArgumentParser(description=DESC) parser.add_argument('in_port', type=int, nargs=1, help='port that RunEngines should broadcast to') parser.add_argument('out_port', type=int, nargs=1, help='port that subscribers should subscribe to') parser.add_argument('--verbose', '-v', action='count', help=("Show 'start' and 'stop' documents. " "(Use -vvv to show all documents.)")) parser.add_argument('--logfile', type=str, help="Redirect logging output to a file on disk.") args = parser.parse_args() in_port = args.in_port[0] out_port = args.out_port[0] if args.verbose: from bluesky.log import config_bluesky_logging # "INFO" if called with '-v' or '-vv', "DEBUG" if called with '-vvv' level = "INFO" if args.verbose <= 2 else 'DEBUG' if args.logfile: config_bluesky_logging(level=level, file=args.logfile) else: config_bluesky_logging(level=level) # Set daemon to kill all threads upon IPython exit threading.Thread(target=start_dispatcher, args=('localhost', out_port), daemon=True).start() print("Connecting...") proxy = Proxy(in_port, out_port) print("Receiving on port %d; publishing to port %d." % (in_port, out_port)) print("Use Ctrl+C to exit.") try: proxy.start() except KeyboardInterrupt: print("Interrupted. Exiting...")
def main(): DESC = "Start a 0MQ proxy for publishing bluesky documents over a network." parser = argparse.ArgumentParser(description=DESC) parser.add_argument('in_port', type=int, nargs=1, help='port that RunEngines should broadcast to') parser.add_argument('out_port', type=int, nargs=1, help='port that subscribers should subscribe to') parser.add_argument('--verbose', '-v', action='count', help=("Show 'start' and 'stop' documents. " "(Use -vvv to show all documents.)")) parser.add_argument('--logfile', type=str, help="Write logfile") args = parser.parse_args() in_port = args.in_port[0] out_port = args.out_port[0] if args.verbose: logger.setLevel('INFO') if args.verbose > 2: logger.setLevel('DEBUG') # Set daemon to kill all threads upon IPython exit threading.Thread(target=start_dispatcher, args=('localhost', out_port, args.logfile), daemon=True).start() print("Connecting...") proxy = Proxy(in_port, out_port) print("Receiving on port %d; publishing to port %d." % (in_port, out_port)) print("Use Ctrl+C to exit.") try: proxy.start() except KeyboardInterrupt: print("Interrupted. Exiting...")
def test_zmq_components(): # The test `test_zmq` runs Proxy and RemoteDispatcher in a separate # process, which coverage misses. pid = os.getpid() def delayed_sigint(delay): time.sleep(delay) os.kill(os.getpid(), signal.SIGINT) proxy = Proxy(5567, 5568) assert not proxy.closed threading.Thread(target=delayed_sigint, args=(5, )).start() try: proxy.start() # delayed_sigint stops the proxy except KeyboardInterrupt: ... assert proxy.closed with pytest.raises(RuntimeError): proxy.start() proxy = Proxy() # random port threading.Thread(target=delayed_sigint, args=(5, )).start() try: proxy.start() # delayed_sigint stops the proxy except KeyboardInterrupt: ... repr(proxy) # test that two ways of specifying address are equivalent d = RemoteDispatcher('localhost:5555') assert d.address == ('localhost', 5555) d = RemoteDispatcher(('localhost', 5555)) assert d.address == ('localhost', 5555) repr(d)
def test_zmq_components(): # The test `test_zmq` runs Proxy and RemoteDispatcher in a separate # process, which coverage misses. pid = os.getpid() def delayed_sigint(delay): time.sleep(delay) os.kill(os.getpid(), signal.SIGINT) proxy = Proxy(5567, 5568) assert not proxy.closed threading.Thread(target=delayed_sigint, args=(5,)).start() try: proxy.start() # delayed_sigint stops the proxy except KeyboardInterrupt: ... assert proxy.closed with pytest.raises(RuntimeError): proxy.start() proxy = Proxy() # random port threading.Thread(target=delayed_sigint, args=(5,)).start() try: proxy.start() # delayed_sigint stops the proxy except KeyboardInterrupt: ... repr(proxy) # test that two ways of specifying address are equivalent d = RemoteDispatcher('localhost:5555') assert d.address == ('localhost', 5555) d = RemoteDispatcher(('localhost', 5555)) assert d.address == ('localhost', 5555) repr(d)
def proxy(): print('Starting Proxy...') proxy = Proxy(5567, 5568) proxy.start()