Last active
May 10, 2022 11:53
-
-
Save travishen/94240442e46598ae550922dd01bae82b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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