python-trio / python-trio/trio

Main thread recognition broken when embedding

Open
#2,564 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

threads
Dominant language
Python
Stars
7.3k
Forks
431
Avg merge
2d 17h
Merged PRs (30d)
6

Description

Trying to use Trio in a Python installation that already has installed a C level SIGINT handler fails.

        File "/usr/lib/python3/dist-packages/trio/_util.py", line 79, in is_main_thread
          signal.signal(signal.SIGINT, signal.getsignal(signal.SIGINT))
        File "/usr/lib/python3.11/signal.py", line 56, in signal
          handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in trio/_util.py at is_main_thread, using the traceback as the entry point. Reproduce the failure with an installed C-level SIGINT handler and inspect the existing signal-based recognition logic. Done means embedded use no longer raises the reported TypeError in this situation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.