Skip to content
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

[main] RuntimeError: set_wakeup_fd only works in main thread #6382

Closed
devos50 opened this issue Sep 28, 2021 · 1 comment · Fixed by #6383
Closed

[main] RuntimeError: set_wakeup_fd only works in main thread #6382

devos50 opened this issue Sep 28, 2021 · 1 comment · Fixed by #6383

Comments

@devos50
Copy link
Contributor

devos50 commented Sep 28, 2021

Encountered during the tests on Linux (in particular, src.tribler-core.tribler_core.components.metadata_store.tests.test_metadata_store_component.test_metadata_store_component):

self = <_UnixSelectorEventLoop running=False closed=False debug=False>
sig = <Signals.SIGCHLD: 17>
callback = <bound method BaseChildWatcher._sig_chld of <asyncio.unix_events.SafeChildWatcher object at 0x7facd585bbe0>>
args = ()

    def add_signal_handler(self, sig, callback, *args):
        """Add a handler for a signal.  UNIX only.
    
        Raise ValueError if the signal number is invalid or uncatchable.
        Raise RuntimeError if there is a problem setting up the handler.
        """
        if (coroutines.iscoroutine(callback) or
                coroutines.iscoroutinefunction(callback)):
            raise TypeError("coroutines cannot be used "
                            "with add_signal_handler()")
        self._check_signal(sig)
        self._check_closed()
        try:
            # set_wakeup_fd() raises ValueError if this is not the
            # main thread.  By calling it early we ensure that an
            # event loop running in another thread cannot add a signal
            # handler.
>           signal.set_wakeup_fd(self._csock.fileno())
E           ValueError: set_wakeup_fd only works in main thread

/usr/lib/python3.8/asyncio/unix_events.py:95: ValueError

During handling of the above exception, another exception occurred:

pyfuncitem = <Function test_metadata_store_component>

    def pytest_pyfunc_call(pyfuncitem):  # type: ignore
        """
        Run coroutines in an event loop instead of a normal function call.
        """
        fast = pyfuncitem.config.getoption("--aiohttp-fast")
        if asyncio.iscoroutinefunction(pyfuncitem.function):
            existing_loop = pyfuncitem.funcargs.get('proactor_loop')\
                or pyfuncitem.funcargs.get('loop', None)
            with _runtime_warning_context():
>               with _passthrough_loop_context(existing_loop, fast=fast) as _loop:

/usr/local/lib/python3.8/dist-packages/aiohttp/pytest_plugin.py:167: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3.8/contextlib.py:113: in __enter__
    return next(self.gen)
/usr/local/lib/python3.8/dist-packages/aiohttp/pytest_plugin.py:145: in _passthrough_loop_context
    loop = setup_test_loop()
/usr/local/lib/python3.8/dist-packages/aiohttp/test_utils.py:528: in setup_test_loop
    watcher.attach_loop(loop)
/usr/lib/python3.8/asyncio/unix_events.py:927: in attach_loop
    loop.add_signal_handler(signal.SIGCHLD, self._sig_chld)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <_UnixSelectorEventLoop running=False closed=False debug=False>
sig = <Signals.SIGCHLD: 17>
callback = <bound method BaseChildWatcher._sig_chld of <asyncio.unix_events.SafeChildWatcher object at 0x7facd585bbe0>>
args = ()

    def add_signal_handler(self, sig, callback, *args):
        """Add a handler for a signal.  UNIX only.
    
        Raise ValueError if the signal number is invalid or uncatchable.
        Raise RuntimeError if there is a problem setting up the handler.
        """
        if (coroutines.iscoroutine(callback) or
                coroutines.iscoroutinefunction(callback)):
            raise TypeError("coroutines cannot be used "
                            "with add_signal_handler()")
        self._check_signal(sig)
        self._check_closed()
        try:
            # set_wakeup_fd() raises ValueError if this is not the
            # main thread.  By calling it early we ensure that an
            # event loop running in another thread cannot add a signal
            # handler.
            signal.set_wakeup_fd(self._csock.fileno())
        except (ValueError, OSError) as exc:
>           raise RuntimeError(str(exc))
E           RuntimeError: set_wakeup_fd only works in main thread

/usr/lib/python3.8/asyncio/unix_events.py:97: RuntimeError

This was supposed to be fixed by #6354 but it seems that it requires a bit more attention.

@ichorid
Copy link
Contributor

ichorid commented Sep 28, 2021

Well, we're still missing pytest.mark.asyncio decorators (or statements) on some tests...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants