python-trio / python-trio/trio

Support Pythonista (iOS python environment)

Open
#684 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

@mikaelho reports in https://github.com/python-trio/trio/issues/673#issuecomment-424958895 that on Pythonista, signal.getsignal(signal.SIGINT) has been hacked somehow to return None. But trio._util.is_main_thread assumes that the return value from getsignal is a valid input to signal; specifically it does:

signal.signal(signal.SIGINT, signal.getsignal(signal.SIGINT))

But when getsignal returns None, this doesn't work, so is_main_thread crashes, and this makes trio unusable in Pythonista.

I'm not really sure how Pythonista works or what the right thing to do here is... in regular Python, getsignal cannot return None, so I guess we can detect when we're on Pythonista, but then what? Does iOS even have signals? Does Pythonista have any way to do control-C?

A simple hack would be to add a check for getsignal returning None, and if it does then return False from is_main_thread – this would effectively disable signal handling on Pythonista, which seems like plausibly the right thing to do?

We might need to rewrite is_main_thread entirely anyway, to fix #673.

@mikaelho While we're at it, what does this return on Pythonista?

signal.signal(signal.SIGINT, signal.SIG_DFL)

?

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 at trio._util.is_main_thread and reproduce Pythonista's signal.getsignal(signal.SIGINT) behavior, comparing it with the regular-Python assumption described here and the related #673 discussion. Determine whether signal.signal(signal.SIGINT, signal.SIG_DFL) works there and define support as avoiding the crash without breaking main-thread or signal behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.