[Feature]: Add support for Cython
See original GitHub issuePlaywright version
1.12.1
Operating system
Linux
What browsers are you seeing the problem on?
Chromium
Other information
Python: 3.8.6 Cython: 0.29.21
What happened? / Describe the bug
Use Cython to compile the code into a so file and run it to prompt an error
Error dispatching the event Traceback (most recent call last):
File "/home/sky/.local/lib/python3.8/site-packages/playwright/_impl/_connection.py", line 273, in _dispatch
object._channel.emit(method, self._replace_guids_with_channels(params))
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_base.py", line 113, in emit
handled = self._call_handlers(event, args, kwargs)
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_base.py", line 96, in _call_handlers
self._emit_run(f, args, kwargs)
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_asyncio.py", line 42, in _emit_run
self.emit('error', exc)
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_base.py", line 116, in emit
self._emit_handle_potential_error(event, args[0] if args else None)
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_base.py", line 86, in _emit_handle_potential_error
raise error
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_asyncio.py", line 40, in _emit_run
coro = f(*args, **kwargs)
File "/home/sky/.local/lib/python3.8/site-packages/playwright/_impl/_cdp_session.py", line 27, in <lambda>
self._channel.on("event", lambda params: self._on_event(params))
File "/home/sky/.local/lib/python3.8/site-packages/playwright/_impl/_cdp_session.py", line 30, in _on_event
self.emit(params["method"], parse_result(params["params"]))
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_base.py", line 113, in emit
handled = self._call_handlers(event, args, kwargs)
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_base.py", line 96, in _call_handlers
self._emit_run(f, args, kwargs)
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_asyncio.py", line 42, in _emit_run
self.emit('error', exc)
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_base.py", line 116, in emit
self._emit_handle_potential_error(event, args[0] if args else None)
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_base.py", line 86, in _emit_handle_potential_error
raise error
File "/home/sky/.local/lib/python3.8/site-packages/pyee/_asyncio.py", line 40, in _emit_run
coro = f(*args, **kwargs)
File "/home/sky/.local/lib/python3.8/site-packages/playwright/_impl/_impl_to_api_mapping.py", line 88, in wrapper_func
arg_count = len(inspect.signature(handler).parameters)
File "/usr/lib/python3.8/inspect.py", line 3093, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
File "/usr/lib/python3.8/inspect.py", line 2842, in from_callable
return _signature_from_callable(obj, sigcls=cls,
File "/usr/lib/python3.8/inspect.py", line 2296, in _signature_from_callable
return _signature_from_builtin(sigcls, obj,
File "/usr/lib/python3.8/inspect.py", line 2107, in _signature_from_builtin
raise ValueError("no signature found for builtin {!r}".format(func))
ValueError: no signature found for builtin <cyfunction BaseSpider.async_init_hook.<locals>.<lambda> at 0x7f5aee512520>
Code snippet to reproduce your bug
from playwright.async_api import async_playwright
def handle_dialog(request):
pass
def finished_log(response):
pass
def response_log(request):
pass
def request_will_log(request):
pass
def response_received_log(request):
pass
def init_hook(page):
page.on("dialog", handle_dialog)
page.on("response", lambda response: response_log(response))
page.on("requestfinished", lambda response: finished_log(response))
async def async_init_hook(page):
client = await page.context.new_cdp_session(page)
await client.send("Network.enable")
client.on("Network.requestWillBeSent", lambda request: request_will_log(request))
client.on("Network.responseReceived", lambda response: response_received_log(response))
init_hook(page)
async def run_main():
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await async_init_hook(page)
await page.goto("https://baidu.com")
print(await page.title())
await browser.close()
Relevant log output
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Building Cython code — Cython 3.0.0a11 documentation
To enable support for Cython compilation, install Cython as described in the installation guide and load the Cython extension from within the Jupyter...
Read more >Cython: C-Extensions for Python
The Cython language is a superset of the Python language that additionally supports calling C functions and declaring C types on variables and...
Read more >Cython support | PyCharm Documentation - JetBrains
PyCharm provides initial Cython support out of the box. PyCharm recognizes .pyx, .pxd, and .pxi files, and allows you to edit them.
Read more >Accelerating Python on GPUs with nvc++ and Cython
Cython interacts naturally with other Python packages for scientific computing and data analysis, with native support for NumPy arrays and the ...
Read more >FLIP-121: Support Cython Optimizing Python User Defined
In release 1.10, we focused on supporting UDF features and did not make many optimizations in terms of performance. Although we have made...
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
@mxschmitt fyi it is “Cython” not “CPython”
Closed since this is not a Playwright bug and more a Cython bug. By that its not fixable from our side.