Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def connection_handler(...):
- ...
- async def test(stop_request):
- # occasionally stop the server
- while True:
- await asyncio.sleep(1)
- print('requesting stop')
- stop_request.set()
- async def main():
- stop_request = asyncio.Event()
- asyncio.create_task(test(stop_request))
- while True:
- print('starting the server')
- server = await websockets.serve(connection_handler, 'localhost', 6789)
- await stop_request.wait()
- stop_request.clear()
- print('stopping the server')
- server.close()
- await server.wait_closed()
- asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement