import re import sys from notebook.notebookapp import main from qulab.utils import ShutdownBlocker if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) with ShutdownBlocker('jupyter-notebook'): sys.exit(main())
parser = argparse.ArgumentParser(description='Run an classfiler server.') parser.add_argument('--name', '-n', default='Classfiler', help='server name') parser.add_argument('--num', '-N', type=int, default=100, help='number of qubits') parser.add_argument('--no-retry', action='store_true', help='no retry') args = parser.parse_args() title = f'{args.name}' if args.no_retry: main(args) else: with ShutdownBlocker(title): cmd = [ sys.executable, __file__, '-n', args.name, '-N', args.num, '--no-retry' ] while True: proc = subprocess.Popen(cmd) proc.wait() if proc.returncode == 0: break
import asyncio import logging from qulab.sugar import getDHT from qulab.utils import ShutdownBlocker log = logging.getLogger() log.addHandler(logging.StreamHandler()) async def start(): dht = await getDHT() print('DHT listen on kad://*:%d' % dht.port) if __name__ == '__main__': loop = asyncio.get_event_loop() asyncio.ensure_future(start(), loop=loop) try: with ShutdownBlocker('DHT'): loop.run_forever() except KeyboardInterrupt: loop.close()