Skip to content

Conversation

@njsmith
Copy link
Member

@njsmith njsmith commented Mar 22, 2017

As compared to the CFFI-based code that this replaces, it's (a) less
race-y (the Python C-level signal handler writes to the
wakeup_fd after setting the flag to run the Python-level signal
handler, whereas our old code ran before), (b) avoids arcane CFFI
stuff that might be broken in the presence of subinterpreters, (c)
slightly less code.

The downside of set_wakeup_fd is that writing to the wakeup socket
fails with EWOULDBLOCK, then in our context the correct thing to do is
to ignore that error (we just want to guarantee a wakeup, and if the
send buffer is full then we are definitely going to wake up), but the
hardcoded behavior in signalmodule.c is to print a spurious warning to
stderr. IMO this is makes it useless to us on Unix-likes, because they
get signals all the time, and we configure out wakeup socket to use a
tiny send buffer to save on kernel memory. But on Windows the
trade-offs are different: Windows insists on using a gargantuan send
buffer (see comments in _wakeup_socketpair.py), and the only signal is
control-C. It's not that big a deal if someone gets a spurious error
message in an extremely rare case when responding to an explicit
control-C. (Though it still would be nicer to not have this error
message...)

See gh-42 for more details.

As compared to the CFFI-based code that this replaces, it's (a) less
race-y (the Python C-level signal handler writes to the
wakeup_fd *after* setting the flag to run the Python-level signal
handler, whereas our old code ran before), (b) avoids arcane CFFI
stuff that might be broken in the presence of subinterpreters, (c)
slightly less code.

The downside of set_wakeup_fd is that writing to the wakeup socket
fails with EWOULDBLOCK, then in our context the correct thing to do is
to ignore that error (we just want to guarantee a wakeup, and if the
send buffer is full then we are definitely going to wake up), but the
hardcoded behavior in signalmodule.c is to print a spurious warning to
stderr. IMO this is makes it useless to us on Unix-likes, because they
get signals all the time, and we configure out wakeup socket to use a
tiny send buffer to save on kernel memory. But on Windows the
trade-offs are different: Windows insists on using a gargantuan send
buffer (see comments in _wakeup_socketpair.py), and the only signal is
control-C. It's not that big a deal if someone gets a spurious error
message in an extremely rare case when responding to an explicit
control-C. (Though it still would be nicer to not have this error
message...)

See python-triogh-42 for more details.
@codecov-io
Copy link

codecov-io commented Mar 22, 2017

Codecov Report

Merging #108 into master will increase coverage by 0.03%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #108      +/-   ##
==========================================
+ Coverage   98.24%   98.28%   +0.03%     
==========================================
  Files          50       50              
  Lines        5878     5875       -3     
  Branches      464      464              
==========================================
- Hits         5775     5774       -1     
+ Misses         88       86       -2     
  Partials       15       15
Impacted Files Coverage Δ
trio/_core/_wakeup_socketpair.py 100% <100%> (ø) ⬆️
trio/_core/_io_windows.py 75.88% <100%> (+0.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa091e2...7b6380b. Read the comment docs.

@njsmith njsmith merged commit 5aaf6a8 into python-trio:master Mar 22, 2017
@njsmith njsmith deleted the use-set_wakeup_fd-on-windows branch March 22, 2017 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants