Is this pythonic?
Marko Rauhamaa
marko at pacujo.net
Thu Nov 24 08:10:06 EST 2016
Chris Angelico <rosuav at gmail.com>:
> On Thu, Nov 24, 2016 at 10:14 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> When you use threads, you call read(2) in the blocking mode. Then the
>> read(2) operation will block "for ever." There's no clean way to
>> cancel the system call.
>
> Signals will usually interrupt system calls, causing them to return
> EINTR. There are exceptions (the aforementioned uninterruptible calls,
> but they're not available in nonblocking form, so they're the same for
> threads and coroutines), but the bulk of system calls will halt
> cleanly on receipt of a signal. And yes, you CAN send signals to
> specific threads; there are limitations, but for a language like
> Python, there's no difficulty in having a single disposition for (say)
> SIGINT, and then using thread signalling to figure out which thread
> should have KeyboardInterrupt raised in it.
Yes, pthread_kill(3) has been made available in Python-3.3, I'm
noticing.
Also:
Changed in version 3.5: Python now retries system calls when a
syscall is interrupted by a signal, except if the signal handler
raises an exception (see PEP 475 for the rationale), instead of
raising InterruptedError.
<URL: https://docs.python.org/3/library/exceptions.html#Interrupt
edError>
Marko
More information about the Python-list
mailing list