Skip to content

Instantly share code, notes, and snippets.

@travishen
Last active May 10, 2022 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travishen/94240442e46598ae550922dd01bae82b to your computer and use it in GitHub Desktop.
Save travishen/94240442e46598ae550922dd01bae82b to your computer and use it in GitHub Desktop.
def main(addr='127.0.0.1', port=2323):
port = int(port)
loop = asyncio.get_event_loop()
server_coro = asyncio.start_server(handle_quries, address, port, loop=loop)
# Drive server_coro to bring up the server
server = loop.run_until_complete(server_coro)
host = server.sockets[0].getsockname()
print(f'Serving on {host}. Hit CTRL-C to stop.')
try:
# Run the event loop, this is the where main will block
loop.run_forever()
except KeyboardInterrupt:
pass
print('Server shutting down.)
server.close()
loop.run_until_compelete(server.wait.closed())
loop.close()
if __name__ == '__main__':
main(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment