-
Notifications
You must be signed in to change notification settings - Fork 939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"RuntimeError: This event loop is already running" When attempting REPL example #178
Comments
for iPython / Jupiter notebooks it seems like the current workaround would be to use that before you run your shell:
Out of curiosity to understand more the user case. You are trying out Playwright in a REPL or are you using it only with with the REPL in the end? |
@mxschmitt thanks for the quick response! In [1]: import nest_asyncio
In [2]: nest_asyncio.apply()
In [3]: from playwright import sync_playwright
In [4]: playwright = sync_playwright().start()
In [5]: My use-case within IPython is largely API exploration and interactive process development before writing a script or integration with an application. Additional note, your example works perfectly in the base python REPL. |
@mxschmitt - FYI, the nested async doesn't work for jupyter notebooks for at least the sync REPL example:
|
@bubthegreat: This looks like a We do install this more capable |
I assume upgrading to 3.9 would improve this, still saw issues, and downgraded to 3.8.3 - still having issues with sync_playwright:
|
Currently, playwright disallows attaching to a running loop: playwright-python/playwright/main.py Lines 79 to 83 in d98d38b
This should be fine in plain IPython (does not launch an asyncio event loop in the main thread), but will fail in Jupyter that uses As calling Minimal reproducible example that will run in latest IPython, but will break on Jupyter environments that use import asyncio
print(asyncio.run(asyncio.sleep(0))) So for Jupyter, additionally a |
My understanding is that resolving this requires cooperation between the embedder that controls the loop and sync Playwright that also wants to dispatch its messages forever. And I don't think such cooperation is the right way to go. Sync API is designed as self-contained, assumes it controls execution. Is there a way to use async in Jupyter? |
If I get time tonight ill play around with it- I dont see any reason for it
not to run in the existing loop - or are there architectural challenges
with it sharing the loop?
…On Tue, Oct 6, 2020, 8:35 AM Pavel Feldman ***@***.***> wrote:
My understanding is that resolving this requires cooperation between the
embedder that controls the loop and sync Playwright that also wants to
dispatch its messages forever. And I don't think such cooperation is the
right way to go. Sync API is designed as self-contained, assumes it
controls execution. Is there a way to use async in Jupyter?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#178 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC5CHIMV52GR76C7R7XFYKTSJMTMLANCNFSM4QLBAFHQ>
.
|
Executing a cell in Jupyter will actually require a lock on the main loop from ipykernel, so you could schedule execution of a Future in one cell (which will start execution once that cell has finished), and get the result in the next cell. Doing it all in one cell is certainly not trivial without nested loops. |
Was just bitten by this. It is very convenient to use Jupyter for explorative programming, especially when the thing you're working with is heavy (like a browser in a particular state). Also ran into this cute tutorial demonstrating why this is nice (he's using Selenium): https://medium.com/shakuro/adopting-ipython-jupyter-for-selenium-testing-d02309dd00b8 The stated workaround sadly didn't work for me, neither on sync nor async versions. Hope this helps! |
Found a workaround for getting Playwright working within Jupyter. It leverages an awesome python library called RPyc to run Playwright outside of the kernel while keeping the API the same. !pip install rpyc
import rpyc
import subprocess
subprocess.Popen('rpyc_classic.py -m forking'.split()) # start RPyc worker
conn = rpyc.classic.connect('localhost')
rplaywright = conn.modules['playwright']
# rplaywright has the same API as playwright
pr = rplaywright.sync_playwright().start()
browser = pr.chromium.launch()
page = browser.newPage()
page.goto('http://whatsmyuseragent.org/')
page.screenshot(path='example.png')
browser.close() # Grab screen
from PIL import Image
from io import BytesIO
browser = pr.chromium.launch()
page = browser.newPage()
page.goto('http://localhost:4000/v/tf3nhh')
img=page.screenshot(path='example.png')
Image.open(BytesIO(img)) |
Hi tals, I follow the wolkaround that you mentioned, however, seems it can't help in win10. The error info shows "OSError: [WinError 193] %1 is not a valid Win32 application" The complete error is as follows. Thanks for any further info. OSError Traceback (most recent call last) c:\program files\python38\lib\subprocess.py in init(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text) c:\program files\python38\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session) OSError: [WinError 193] %1 is not a valid Win32 application |
@wohenniubi sorry don't have a windows machine to test this out, but try figuring out how to run the rpyc_classic.py program on command line first |
@tals Thanks for the response. After several trials without success, I might switch back to use selenium by now.
|
Closed for now as part of the triage. Please reopen if it's still persistent. |
@mxschmitt not sure why its closed - this problem still exists. You can reproduce this on the latest versions of jupyter+playwright |
The bug is upstream: ipython/ipykernel#548 And there is a workaround: #178 (comment) Maybe could warn the jupyter user with a verbose re-raising try-except? |
@ddelange the proposed workaround sadly doesn't work on jupyter: #178 (comment) The only thing I could do to get it working was running it outside of the process with RPyc |
It's been almost two years and this still isn't fixed that I can find - playwright is explicitly stopping me from using nested loops:
The workarounds don't work for those of us using windows, and they don't appear to work in WSL either - is there a reason we can't get more information on why this is still closed two years later with no traction and no functional workarounds for presumably a fairly normal use case of using a jupyter notebook for exploratory programming? It seems hard to believe that we just assume everyone will use raw iPython for everything so I'm confused by the reluctance to actually fix this. If I'm understanding the asyncio base_events.py error, it's because there's no implementation of the |
@tals Rpyc will only works if we will not call any playwright sub-modules directly, tomerfiliba-org/rpyc#496. |
still waiting i want to leave selenium but this stop me |
If you want to use an async framework (playwright-python is natively async) inside Jupyter Notebooks, the ipykernel maintainer suggests to use the async api directly ( |
still does not work in jupyter (vscode interactive). Sync API is not allowed! import asyncio
from playwright.async_api import async_playwright
from playwright.sync_api import sync_playwright
# https://github.com/microsoft/playwright-python/issues/178#issuecomment-680249269
import nest_asyncio
nest_asyncio.apply()
# Error: It looks like you are using Playwright Sync API inside the asyncio loop.
# Please use the Async API instead.
p = sync_playwright().start() Async API is not worked! import asyncio
from playwright.async_api import async_playwright
from playwright.sync_api import sync_playwright
# https://github.com/microsoft/playwright-python/issues/178#issuecomment-680249269
import nest_asyncio
nest_asyncio.apply()
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(channel="chrome",headless=False, slow_mo=100)
page = await browser.new_page()
await page.goto("https://cnki.net/")
await browser.close()
# NotImplementedError
asyncio.run(main()) Maybe I should switch to selenium, see run-selenium-in-jupyter-notebook-on-wsl2-or-ubuntu。 |
can you try the async snippet without |
Here is my snapshot and error logs.
|
this error is coming from |
It seems sync API is not work in plain python script. The following code just launch browser, open page then exit. I did not call from playwright.sync_api import sync_playwright
p = sync_playwright().start()
browser = p.chromium.launch(channel="chrome",headless=False, slow_mo=100)
page = browser.new_page()
page.goto('https://cnki.net/') Here is ipython error logs. C:\Users\Liu.D.H>ipython
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from playwright.sync_api import sync_playwright
...:
...: p = sync_playwright().start()
...: browser = p.chromium.launch(channel="chrome",headless=False, slow_mo=100)
...: page = browser.new_page()
...: page.goto('https://cnki.net/')
Out[1]: <Response url='https://cnki.net/' request=<Request url='https://cnki.net/' method='GET'>>
Traceback (most recent call last):
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\Scripts\ipython.exe\__main__.py", line 7, in <module>
sys.exit(start_ipython())
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\site-packages\IPython\__init__.py", line 124, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\site-packages\traitlets\config\application.py", line 976, in launch_instance
app.start()
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\site-packages\IPython\terminal\ipapp.py", line 318, in start
self.shell.mainloop()
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\site-packages\IPython\terminal\interactiveshell.py", line 685, in mainloop
self.interact()
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\site-packages\IPython\terminal\interactiveshell.py", line 670, in interact
code = self.prompt_for_code()
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\site-packages\IPython\terminal\interactiveshell.py", line 609, in prompt_for_code
text = self.pt_app.prompt(
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 1034, in prompt
return self.app.run(
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\site-packages\prompt_toolkit\application\application.py", line 937, in run
return loop.run_until_complete(
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 622, in run_until_complete
self._check_running()
File "C:\Users\Liu.D.H\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 582, in _check_running
raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running
If you suspect this is an IPython 8.5.0 bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
sys:1: RuntimeWarning: coroutine 'Application.run_async' was never awaited
C:\Users\Liu.D.H> |
I restarted the kernel, the errors changed. I run the following code block. async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(channel="chrome",headless=False, slow_mo=100)
page = await browser.new_page()
await page.goto("https://cnki.net/")
await browser.close()
asyncio.run(main())
|
instead of |
I tried, but still not work.
|
I also tried logs
|
I have no problem running the example on a fresh jupyter server: The fact that your traceback hangs here:
Makes me think you might not be running in a clean jupyter environment. Maybe vscode does some magic? |
Hi, I tried to update jupyter via import asyncio
from playwright.async_api import async_playwright
async def run(playwright):
chromium = playwright.chromium
browser = await chromium.launch(channel="chrome",headless=False, slow_mo=100).launch()
page = await browser.new_page()
await page.goto("https://example.com")
await browser.close()
async def main():
async with async_playwright() as playwright:
await run(playwright)
await main() logsC:\Users\Liu.D.H>pip install -U jupyterlab notebook voila
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: jupyterlab in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (3.4.7)
Collecting jupyterlab
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2b/d4/e0627f216bfb451e807cb8c2c8a0fc27e47cc76e483e539e8e213b95518e/jupyterlab-3.5.0-py3-none-any.whl (8.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.8/8.8 MB 9.2 MB/s eta 0:00:00
Requirement already satisfied: notebook in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (6.4.12)
Collecting notebook
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/db/40/2d321ba572dc9a94a090d92c9826291a1dcee1e05bc6c1d641ce419b701d/notebook-6.5.2-py3-none-any.whl (439 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 439.1/439.1 kB 9.1 MB/s eta 0:00:00
Requirement already satisfied: voila in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (0.3.6)
Collecting voila
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ce/63/55971b7c40ab1c4d87beec34775811b8aeea9a123b2d0abc41febc58526c/voila-0.4.0-py3-none-any.whl (5.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.5/5.5 MB 11.0 MB/s eta 0:00:00
Requirement already satisfied: nbclassic in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (0.4.3)
Requirement already satisfied: packaging in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (21.3)
Requirement already satisfied: jupyterlab-server~=2.10 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (2.15.0)
Requirement already satisfied: jupyter-core in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (4.11.1)
Requirement already satisfied: jupyter-server<3,>=1.16.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (1.18.1)
Requirement already satisfied: tomli in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (2.0.1)
Requirement already satisfied: jinja2>=2.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (3.1.2)
Requirement already satisfied: ipython in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (8.5.0)
Requirement already satisfied: tornado>=6.1.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab) (6.2)
Requirement already satisfied: terminado>=0.8.3 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (0.15.0)
Requirement already satisfied: ipykernel in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (6.15.1)
Requirement already satisfied: argon2-cffi in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (21.3.0)
Requirement already satisfied: traitlets>=4.2.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (5.3.0)
Requirement already satisfied: nest-asyncio>=1.5 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (1.5.5)
Requirement already satisfied: nbconvert>=5 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (6.5.3)
Requirement already satisfied: ipython-genutils in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (0.2.0)
Requirement already satisfied: jupyter-client>=5.3.4 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (7.3.4)
Collecting nbclassic
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a6/85/2a240df7326b7311ebd926c12d7df5394aef2f9f76ffbb294079cc43960e/nbclassic-0.4.8-py3-none-any.whl (9.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.8/9.8 MB 11.2 MB/s eta 0:00:00
Requirement already satisfied: prometheus-client in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (0.14.1)
Requirement already satisfied: pyzmq>=17 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (23.2.1)
Requirement already satisfied: nbformat in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (5.4.0)
Requirement already satisfied: Send2Trash>=1.8.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from notebook) (1.8.0)
Requirement already satisfied: websockets>=9.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from voila) (10.3)
Requirement already satisfied: nbclient<0.8,>=0.4.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from voila) (0.5.13)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jinja2>=2.1->jupyterlab) (2.1.1)
Requirement already satisfied: python-dateutil>=2.8.2 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyter-client>=5.3.4->notebook) (2.8.2)
Requirement already satisfied: entrypoints in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyter-client>=5.3.4->notebook) (0.4)
Requirement already satisfied: pywin32>=1.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyter-core->jupyterlab) (304)
Requirement already satisfied: anyio<4,>=3.1.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyter-server<3,>=1.16.0->jupyterlab) (3.6.1)
Requirement already satisfied: websocket-client in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyter-server<3,>=1.16.0->jupyterlab) (1.3.3)
Requirement already satisfied: pywinpty in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyter-server<3,>=1.16.0->jupyterlab) (2.0.7)
Requirement already satisfied: babel in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab-server~=2.10->jupyterlab) (2.10.3)
Requirement already satisfied: json5 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab-server~=2.10->jupyterlab) (0.9.9)
Requirement already satisfied: requests in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab-server~=2.10->jupyterlab) (2.28.1)
Requirement already satisfied: jsonschema>=3.0.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jupyterlab-server~=2.10->jupyterlab) (4.10.2)
Requirement already satisfied: notebook-shim>=0.1.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbclassic->jupyterlab) (0.1.0)
Requirement already satisfied: pygments>=2.4.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (2.13.0)
Requirement already satisfied: beautifulsoup4 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (4.11.1)
Requirement already satisfied: pandocfilters>=1.4.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (1.5.0)
Requirement already satisfied: mistune<2,>=0.8.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (0.8.4)
Requirement already satisfied: lxml in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (4.9.1)
Requirement already satisfied: defusedxml in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (0.7.1)
Requirement already satisfied: bleach in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (5.0.1)
Requirement already satisfied: jupyterlab-pygments in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (0.2.2)
Requirement already satisfied: tinycss2 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbconvert>=5->notebook) (1.1.1)
Requirement already satisfied: fastjsonschema in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from nbformat->notebook) (2.16.1)
Requirement already satisfied: argon2-cffi-bindings in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from argon2-cffi->notebook) (21.2.0)
Requirement already satisfied: matplotlib-inline>=0.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipykernel->notebook) (0.1.5)
Requirement already satisfied: psutil in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipykernel->notebook) (5.9.1)
Requirement already satisfied: debugpy>=1.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipykernel->notebook) (1.6.3)
Requirement already satisfied: backcall in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipython->jupyterlab) (0.2.0)
Requirement already satisfied: prompt-toolkit<3.1.0,>3.0.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipython->jupyterlab) (3.0.30)
Requirement already satisfied: decorator in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipython->jupyterlab) (5.1.1)
Requirement already satisfied: pickleshare in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipython->jupyterlab) (0.7.5)
Requirement already satisfied: jedi>=0.16 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipython->jupyterlab) (0.18.1)
Requirement already satisfied: colorama in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipython->jupyterlab) (0.4.5)
Requirement already satisfied: stack-data in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from ipython->jupyterlab) (0.4.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from packaging->jupyterlab) (3.0.9)
Requirement already satisfied: idna>=2.8 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from anyio<4,>=3.1.0->jupyter-server<3,>=1.16.0->jupyterlab) (3.3)
Requirement already satisfied: sniffio>=1.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from anyio<4,>=3.1.0->jupyter-server<3,>=1.16.0->jupyterlab) (1.2.0)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jedi>=0.16->ipython->jupyterlab) (0.8.3)
Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jsonschema>=3.0.1->jupyterlab-server~=2.10->jupyterlab) (0.18.1)
Requirement already satisfied: attrs>=17.4.0 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from jsonschema>=3.0.1->jupyterlab-server~=2.10->jupyterlab) (22.1.0)
Requirement already satisfied: wcwidth in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from prompt-toolkit<3.1.0,>3.0.1->ipython->jupyterlab) (0.2.5)
Requirement already satisfied: six>=1.5 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from python-dateutil>=2.8.2->jupyter-client>=5.3.4->notebook) (1.16.0)
Requirement already satisfied: cffi>=1.0.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from argon2-cffi-bindings->argon2-cffi->notebook) (1.15.1)
Requirement already satisfied: pytz>=2015.7 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from babel->jupyterlab-server~=2.10->jupyterlab) (2022.2.1)
Requirement already satisfied: soupsieve>1.2 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from beautifulsoup4->nbconvert>=5->notebook) (2.3.2.post1)
Requirement already satisfied: webencodings in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from bleach->nbconvert>=5->notebook) (0.5.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from requests->jupyterlab-server~=2.10->jupyterlab) (2022.6.15)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from requests->jupyterlab-server~=2.10->jupyterlab) (1.26.11)
Requirement already satisfied: charset-normalizer<3,>=2 in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from requests->jupyterlab-server~=2.10->jupyterlab) (2.1.0)
Requirement already satisfied: executing in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from stack-data->ipython->jupyterlab) (0.10.0)
Requirement already satisfied: asttokens in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from stack-data->ipython->jupyterlab) (2.0.8)
Requirement already satisfied: pure-eval in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from stack-data->ipython->jupyterlab) (0.2.2)
Requirement already satisfied: pycparser in c:\users\liu.d.h\appdata\local\programs\python\python310\lib\site-packages (from cffi>=1.0.1->argon2-cffi-bindings->argon2-cffi->notebook) (2.21)
Installing collected packages: voila, nbclassic, notebook, jupyterlab
Attempting uninstall: voila
Found existing installation: voila 0.3.6
Uninstalling voila-0.3.6:
Successfully uninstalled voila-0.3.6
Attempting uninstall: nbclassic
Found existing installation: nbclassic 0.4.3
Uninstalling nbclassic-0.4.3:
Successfully uninstalled nbclassic-0.4.3
Attempting uninstall: notebook
Found existing installation: notebook 6.4.12
Uninstalling notebook-6.4.12:
Successfully uninstalled notebook-6.4.12
Attempting uninstall: jupyterlab
Found existing installation: jupyterlab 3.4.7
Uninstalling jupyterlab-3.4.7:
Successfully uninstalled jupyterlab-3.4.7
Successfully installed jupyterlab-3.5.0 nbclassic-0.4.8 notebook-6.5.2 voila-0.4.0
C:\Users\Liu.D.H>jupyter --version
Selected Jupyter core packages...
IPython : 8.5.0
ipykernel : 6.15.1
ipywidgets : not installed
jupyter_client : 7.3.4
jupyter_core : 4.11.1
jupyter_server : 1.18.1
jupyterlab : 3.5.0
nbclient : 0.5.13
nbconvert : 6.5.3
nbformat : 5.4.0
notebook : 6.5.2
qtconsole : not installed
traitlets : 5.3.0
C:\Users\Liu.D.H>
|
do you get the same traceback when you run the snippet in ipython instead of jupyter? if yes, we eliminated the ipykernel loop issue, and my next guess would be the fact that you're on windows... |
potentially indeed your OS ref https://stackoverflow.com/q/70349876 @mxschmitt would this be caught by the Windows CI? edit: more specifically https://stackoverflow.com/a/44639711/5511061 |
@ddelange Thanks. I found a workaround on windows now. NOT RECOMMEND! From jupyter/notebook#5916, minrk/ipykernel@079f072, https://stackoverflow.com/questions/44633458/why-am-i-getting-notimplementederror-with-async-and-await-on-windows/74311290#74311290, https://github.com/ipython/ipykernel/blob/99a1becaa958b33d80fe337fdbc41305030fdb6d/ipykernel/kernelapp.py#L633-L637. I found a way to make it work hackly (not recommend) on windows. Comment Then the following code will work in jupyter notebook. import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(channel="chrome", headless=False, slow_mo=100)
page = await browser.new_page()
await page.goto("https://cnki.net/")
await browser. Close()
await main() |
I have another question, why can't I use sync API in jupyter? I have to write a lot |
jup it's not allowed |
Not allowed? However, I used a lot of packages like numpy, pandas, matplotlib, tensorflow, pytorch, and so on are sync style of API, most of them are async only. Is there any ways to make sync API of playwright-python work on jupyter? |
I didn't double check, but I'm pretty sure those libraries don't use asyncio under the hood (they may still release the GIL however). For more information on the topic, see ipython/ipykernel#548 (comment). |
Each time I attempt the REPl example, I get the traceback below. Sync context-manager example worked though.
playwright==0.8.0
REPL Example: https://github.com/microsoft/playwright-python#repl-support-without-context-managers
IPython session
The text was updated successfully, but these errors were encountered: