This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Richard Warfield
Recipients Richard Warfield
Date 2019-11-24.06:06:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574575580.88.0.320595380442.issue38904@roundup.psfhosted.org>
In-reply-to
Content
I have an application (https://github.com/litxio/ptghci) using embedded Python, which needs to set a signal handler (and use the prompt-toolkit library which itself sets signal handlers).

My call to signal.signal is guarded by a check that we're running in the main thread:

        if threading.current_thread() is threading.main_thread():
            print (threading.current_thread().name)
            signal.signal(signal.SIGINT, int_handler)

And the above indeed prints "MainThread".  But this raises an exception:

  File "app.py", line 45, in __init__
    signal.signal(signal.SIGINT, int_handler)
  File "/usr/lib/python3.8/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

This seems like something that should not happen.  

Now, I tried to generate a simple replicating example but thus far haven't been able to do so -- simply calling signal.signal from PyRun_SimpleString doesn't do the trick, even within a pthreads thread.
History
Date User Action Args
2019-11-24 06:06:20Richard Warfieldsetrecipients: + Richard Warfield
2019-11-24 06:06:20Richard Warfieldsetmessageid: <1574575580.88.0.320595380442.issue38904@roundup.psfhosted.org>
2019-11-24 06:06:20Richard Warfieldlinkissue38904 messages
2019-11-24 06:06:20Richard Warfieldcreate