Close new event loops in just_run helper#159
Conversation
|
Sigh OK, that's not as simple as it looks. Using I think we could:
|
|
Ugh, now there are random test failures on a parallel test. 😞 |
|
|
|
I suspect it's not directly related, but maybe creating new event loops makes it more likely. I confess I restarted CI twice on the last commit in the hope that the random error would go away, but 3 times in a row there has been one job failing (and not the same one), which suggests that it's made the odds worse. |
I was getting some
__del__errors from a test suite of a project using nbclient:Error traceback
I believe this comes from event loops being created to run nbclient async code, and then never cleaned up. #58 might also be related, but I'm not sure of that.
For Python 3.7 and above, it's easy to use
asyncio.run(), which deals with creating an event loop and closing it again. For Python 3.6, I've added a try/finally to close the event loop after it finishes.In theory there's a slight downside that we have to create a new event loop for each synchronous call. However, I think the typical use case (at least, my use case ;-) ) is to make a single
execute()call to execute an entire notebook, in which case the overhead of creating and tearing down the event loop is probably negligible.