Author jnwatson
Recipients asvetlov, jnwatson, yselivanov
Date 2018-09-14.15:27:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1536938865.53.0.956365154283.issue34679@psf.upfronthosting.co.za>
In-reply-to
Content
Summary:  essentially asyncio.add_signal_handler doesn't work when called off the main thread.  One might consider this a documentation failure.

(Note: there's also a bigger issue with cleanup, which I'll submit separately)

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/home/nic/.pyenv/versions/3.6.4/lib/python3.6/asyncio/unix_events.py", line 91, in add_signal_handler
    signal.set_wakeup_fd(self._csock.fileno())
ValueError: set_wakeup_fd only works in main thread

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/nic/.pyenv/versions/3.6.4/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/nic/.pyenv/versions/3.6.4/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/nic/tmp/signal_event_loop_bug.py", line 14, in do_loop
    loop.add_signal_handler(signal.SIGINT, mysighandler)
  File "/home/nic/.pyenv/versions/3.6.4/lib/python3.6/asyncio/unix_events.py", line 93, in add_signal_handler
    raise RuntimeError(str(exc))
RuntimeError: set_wakeup_fd only works in main thread

Code:

import asyncio
import signal
import threading

def mysighandler():
    pass

def do_loop():
    loop = asyncio.new_event_loop()
    # This will fail with RuntimeError: set_wakeup_fd only works in main thread
    loop.add_signal_handler(signal.SIGINT, mysighandler)
    loop.close()

t = threading.Thread(target=do_loop)
t.start()
t.join()
History
Date User Action Args
2018-09-14 15:27:45jnwatsonsetrecipients: + jnwatson, asvetlov, yselivanov
2018-09-14 15:27:45jnwatsonsetmessageid: <1536938865.53.0.956365154283.issue34679@psf.upfronthosting.co.za>
2018-09-14 15:27:45jnwatsonlinkissue34679 messages
2018-09-14 15:27:45jnwatsoncreate