Skip to content

[BUG] Python3.7 ValueError: signal only works in main thread #1685

Closed
@byehack

Description

@byehack

Context:

  • Playwright Version: 1.28
  • Operating System: Linux
  • Python version: 3.7
  • Browser: Firefox
  • Extra: ran on codespaces.

Code Snippet

from playwright.sync_api import sync_playwright

def my_thread():
    with sync_playwright() as pw:
        pass

threading.Thread(target=my_thread).start()
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "-", line 958, in my_thread
  File "/home/vscode/.local/lib/python3.7/site-packages/playwright/sync_api/_context_manager.py", line 61, in __enter__
    asyncio.set_child_watcher(self._watcher)  # type: ignore
  File "/usr/local/lib/python3.7/asyncio/events.py", line 773, in set_child_watcher
    return get_event_loop_policy().set_child_watcher(watcher)
  File "/usr/local/lib/python3.7/asyncio/unix_events.py", line 1152, in set_child_watcher
    self._watcher.close()
  File "/usr/local/lib/python3.7/asyncio/unix_events.py", line 930, in close
    super().close()
  File "/usr/local/lib/python3.7/asyncio/unix_events.py", line 863, in close
    self.attach_loop(None)
  File "/usr/local/lib/python3.7/asyncio/unix_events.py", line 881, in attach_loop
    self._loop.remove_signal_handler(signal.SIGCHLD)
  File "/usr/local/lib/python3.7/asyncio/unix_events.py", line 147, in remove_signal_handler
    signal.signal(sig, handler)
  File "/usr/local/lib/python3.7/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

It is coming from this patch: #1213
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions