[issue9867] Interrupted system calls are not retried

Armin Ronacher report at bugs.python.org
Thu Sep 16 14:34:05 CEST 2010


Armin Ronacher <armin.ronacher at active-4.com> added the comment:

The following minimal C code shows how EINTR can be handled:

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <signal.h>

#define BUFFER_SIZE 1024


int
main()
{
    char buffer[BUFFER_SIZE];
    printf("PID = %d\n", getpid());
    while (1) {
        int rv = fgetc(stdin);
        if (rv < 0) {
            if (feof(stdin))
                break;
            if (errno == EINTR)
                continue;
            printf("Call failed with %d\n", errno);
            return 1;
        }
        else
            fputc(rv, stdout);
    }
    return 0;
}



Test application:

mitsuhiko at nausicaa:/tmp$ ./a.out 
PID = 22806
Terminated
mitsuhiko at nausicaa:/tmp$ ./a.out 
PID = 22809

mitsuhiko at nausicaa:/tmp$ ./a.out 
PID = 22812
^Z
[2]+  Stopped                 ./a.out
mitsuhiko at nausicaa:/tmp$ fg
./a.out
test
test
foo
foo

First signal sent was TERM, second was INT.  Last case was sending to background, receiving the ignored SIGCONT signal, fgetc returning -1 and fgetc being called again because of errno being EINTR.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9867>
_______________________________________


More information about the Python-bugs-list mailing list