You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 7508 Reporter: goswin Status: acknowledged (set by @xavierleroy on 2017-03-24T17:26:21Z) Resolution: open Priority: normal Severity: feature Category: standard library Monitored by:@diml@yallop
Bug description
I want to push worward something python did recently:
System call wrappers provided in the standard library should be retried automatically when they fail with EINTR , to relieve application code from the burden of doing so.
By system calls, we mean the functions exposed by the standard C library pertaining to I/O or handling of other system resources.
== Rationale ==
=== Interrupted system calls ===
On POSIX systems, signals are common. Code calling system calls must be prepared to handle them. Examples of signals:
The most common signal is SIGINT , the signal sent when CTRL+c is pressed. By default, Python raises a KeyboardInterrupt exception when this signal is received.
When running subprocesses, the SIGCHLD signal is sent when a child process exits.
Resizing the terminal sends the SIGWINCH signal to the applications running in the terminal.
Putting the application in background (ex: press CTRL-z and then type the bg command) sends the SIGCONT signal.
Writing a C signal handler is difficult: only "async-signal-safe" functions can be called (for example, printf() and malloc() are not async-signal safe), and there are issues with reentrancy. Therefore, when a signal is received by a process during the execution of a system call, the system call can fail with the EINTR error to give the program an opportunity to handle the signal without the restriction on signal-safe functions.
In ocaml a signal is caught and recorded in the GC and the next time a GC sequence point is hit the ocaml signal handler is called. Which I believe is eaxctly the same as in Python and we can go the same way to make writing signal safe code more easy. The Unix and Thread modules are directly affected although IO functions in Pervasives should be checked too.
Steps to reproduce
Try using the Graphics module under unix in combination with Unix.sleep. Graphics uses SIGIO to monitor the X connection and thereby aborts the Unix.sleep at random times.
The text was updated successfully, but these errors were encountered:
Unix.sleep in 4.06.0+dev0-2017-02-15 handles EINTR internally and aborts the sleep early when the signal handler throws an exception (if nanosleep or select is available, the sleep syscall is to imprecise to retry). Exactly as requested in this issue.
Unix.select on the other hand still returns Unix.Unix_error(Unix.EINTR, "select", ""). Didn't check anything else after that.
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.
Original bug ID: 7508
Reporter: goswin
Status: acknowledged (set by @xavierleroy on 2017-03-24T17:26:21Z)
Resolution: open
Priority: normal
Severity: feature
Category: standard library
Monitored by: @diml @yallop
Bug description
I want to push worward something python did recently:
https://www.python.org/dev/peps/pep-0475/
== Abstract ==
System call wrappers provided in the standard library should be retried automatically when they fail with EINTR , to relieve application code from the burden of doing so.
By system calls, we mean the functions exposed by the standard C library pertaining to I/O or handling of other system resources.
== Rationale ==
=== Interrupted system calls ===
On POSIX systems, signals are common. Code calling system calls must be prepared to handle them. Examples of signals:
Writing a C signal handler is difficult: only "async-signal-safe" functions can be called (for example, printf() and malloc() are not async-signal safe), and there are issues with reentrancy. Therefore, when a signal is received by a process during the execution of a system call, the system call can fail with the EINTR error to give the program an opportunity to handle the signal without the restriction on signal-safe functions.
In ocaml a signal is caught and recorded in the GC and the next time a GC sequence point is hit the ocaml signal handler is called. Which I believe is eaxctly the same as in Python and we can go the same way to make writing signal safe code more easy. The Unix and Thread modules are directly affected although IO functions in Pervasives should be checked too.
Steps to reproduce
Try using the Graphics module under unix in combination with Unix.sleep. Graphics uses SIGIO to monitor the X connection and thereby aborts the Unix.sleep at random times.
The text was updated successfully, but these errors were encountered: