Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 2, 2021. It is now read-only.

Commit 93a9ce6

Browse files
committed
updated tcp_charfinder.py to Python 3.8 asyncio API
1 parent f39c8ef commit 93a9ce6

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

‎18-asyncio-py3.7/charfinder/tcp_charfinder.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,17 @@ async def handle_queries(reader, writer): # <3>
3838
# END TCP_CHARFINDER_TOP
3939

4040
# BEGIN TCP_CHARFINDER_MAIN
41-
def main(address='127.0.0.1', port=2323): # <1>
41+
asyncdef main(address='127.0.0.1', port=2323): # <1>
4242
port = int(port)
43-
loop = asyncio.get_event_loop()
44-
server_coro = asyncio.start_server(handle_queries, address, port,
45-
loop=loop) # <2>
46-
server = loop.run_until_complete(server_coro) # <3>
43+
server = await asyncio.start_server(handle_queries, address, port) # <2>
4744

48-
host = server.sockets[0].getsockname() # <4>
49-
print('Serving on {}. Hit CTRL-C to stop.'.format(host)) # <5>
50-
try:
51-
loop.run_forever() # <6>
52-
except KeyboardInterrupt: # CTRL+C pressed
53-
pass
45+
host = server.sockets[0].getsockname() # <3>
46+
print('Serving on {}. Hit CTRL-C to stop.'.format(host)) # <4>
5447

55-
print('Server shutting down.')
56-
server.close() # <7>
57-
loop.run_until_complete(server.wait_closed()) # <8>
58-
loop.close() # <9>
48+
async with server:
49+
await server.serve_forever()
5950

6051

6152
if __name__ == '__main__':
62-
main(*sys.argv[1:]) # <10>
53+
asyncio.run(main(*sys.argv[1:])) # <5>
6354
# END TCP_CHARFINDER_MAIN

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /