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

Signal handler setup appears to hang on Windows #2610

Open
dgw opened this issue May 28, 2024 · 0 comments
Open

Signal handler setup appears to hang on Windows #2610

dgw opened this issue May 28, 2024 · 0 comments
Labels
Bug Things to squish; generally used for issues Long-term Planning Things that need to happen at some point in the future, but need to NOT happen soon. Windows

Comments

@dgw
Copy link
Member

dgw commented May 28, 2024

Description

When run on Windows, Sopel appears to hang after asyncio emits the log line, "Using proactor: IocpProactor".

Under the hood, what actually happens here is that the event loop starts, but trying to set up a signal handler (code excerpt below) raises NotImplementedError on Windows and execution stalls.

sopel/sopel/irc/backends.py

Lines 478 to 482 in ab32aca

# register signal handlers
for quit_signal in QUIT_SIGNALS:
self._loop.add_signal_handler(quit_signal, self._signal_quit)
for restart_signal in RESTART_SIGNALS:
self._loop.add_signal_handler(restart_signal, self._signal_restart)

The error and traceback is logged to configname.exceptions.log.

Reproduction steps

  1. Install Sopel on Windows
  2. Try to run it

Expected behavior

Sopel's signal handling needs a rework to behave at least somewhat correctly cross-platform, even if the Windows code path can't fully support all features offered on Unix-like platforms.

There is probably a way to make everything work, with a bit of "AI" (read: if/else checks). I just haven't looked into it because this whole thing ain't getting worked on before 8.1.

Relevant logs

Traceback (most recent call last):
  File "C:\Users\dgw\AppData\Local\Programs\Python\Python312\Lib\site-packages\sopel\cli\run.py", line 78, in run
    p.run(settings.core.host, int(settings.core.port))
  File "C:\Users\dgw\AppData\Local\Programs\Python\Python312\Lib\site-packages\sopel\irc\__init__.py", line 380, in run
    self.backend.run_forever()
  File "C:\Users\dgw\AppData\Local\Programs\Python\Python312\Lib\site-packages\sopel\irc\backends.py", line 562, in run_forever
    asyncio.run(self._run_forever())
  File "C:\Users\dgw\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\dgw\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dgw\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\dgw\AppData\Local\Programs\Python\Python312\Lib\site-packages\sopel\irc\backends.py", line 480, in _run_forever
    self._loop.add_signal_handler(quit_signal, self._signal_quit)
  File "C:\Users\dgw\AppData\Local\Programs\Python\Python312\Lib\asyncio\events.py", line 582, in add_signal_handler
    raise NotImplementedError
NotImplementedError

Notes

If I comment out the add_signal_handler() calls shown above, Sopel runs just fine (modulo #1382 issues with stopping it; one must press Ctrl-C twice to actually stop the bot, else it will reconnect after 20 seconds).

Implementation-wise, the stdlib signal library could help with fixing this.

Line numbers in sopel/irc/backends.py might be slightly off in the traceback I attached because I was modifying my local copy to debug things and did not revert those edits before starting to write this issue.

Sopel version

3261d9c

Installation method

pip install

Python version

3.12.3

Operating system

Windows 11

IRCd

No response

Relevant plugins

No response

@dgw dgw added Bug Things to squish; generally used for issues Windows Long-term Planning Things that need to happen at some point in the future, but need to NOT happen soon. labels May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Things to squish; generally used for issues Long-term Planning Things that need to happen at some point in the future, but need to NOT happen soon. Windows
Projects
None yet
Development

No branches or pull requests

1 participant