In Python3.6.1, after calling loop.close () in a loop retrieved from asyncio.get_event_loop (), can I create a new loop?
I looked at other posts with answers to close the loop correctly, and also how to use task.cancel (), but could not use any of these examples so that a new loop was created after the first close. I also tried to explicitly set the executor and later call executor.shutdown (wait = True), but that didn't help. I also tried "del loop" as well as a bunch of other things.
The documentation indicates that closing the event loop is idempotent and irreversible. Does this mean that a new cycle cannot be created?
Here is an example of a simple example to demonstrate the problem: `
#!/usr/bin/env python3.6 ''' To demonstrate an issue, the following code was adapted from: https://docs.python.org/3/library/asyncio-eventloop.html ''' import asyncio def hello_world(loop): print('Hello World') loop.stop() loop = asyncio.get_event_loop() loop.call_soon(hello_world, loop) loop.run_forever()
code> `
Any attempts to answer my question will be appreciated.
Alternatively, would it be a bad form to create an event loop, use it for a variety of purposes, and then just close this loop when a long running program is about to exit? It just seems wrong.
source share