RuntimeError: Event loop is closed
See original GitHub issueAfter running pip install playwright
and playwright install
, I went to the documentation to try some of the features out. Here is the code which I ran:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
However, I received an error: RuntimeError: Event loop is closed
.
I proceeded to try the same process by with browser=p.firefox.launch()
, but to no avail.
Specifications:
- Python 3.9.2
- Playwright v1.9.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
"Asyncio Event Loop is Closed" when getting loop
As of Python 3.7, the process of creating, managing, then closing the loop (as well as a few other resources) is handled for...
Read more >Python 3.8+ raises "RuntimeError: Event Loop is closed" on ...
aclose finishes, which means the socket is actually deleted upon garbage collection, and by then I suppose the event loop is already closed......
Read more >RuntimeError: Event loop is closed : r/learnpython - Reddit
RuntimeError : Event loop is closed. Currently learning about async, and it's been a real challenge converting sync -> async.
Read more >asyncio.run event loop is closed - You.com | The AI Search ...
This function always creates a new event loop and closes it at the end. This means the event loop is not available for...
Read more >Event Loop — Python 3.11.1 documentation
Raises RuntimeError if called on a loop that's been closed. This can happen on a secondary thread when the main application is shutting...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I was able to solve it, assuming my fix is relevant to the warning. I spent a while debugging and one of my tests didn’t call
browser.close()
before callingp.stop()
(from the above comment). I haven’t seen the warning message much after fixing this, so I think this may be the solution to my issue.Sorry for the late reply. Your snippet looks correct, but we need more information to address this. Could you run your snippet with the
DEBUG=pw:browser*
environment variable set? That would help us identifying the issue.