question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeError: Event loop is closed

See original GitHub issue

After 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:closed
  • Created 3 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JacobLee23commented, Mar 31, 2021

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 calling p.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.

0reactions
pavelfeldmancommented, Mar 30, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found