Signal-handling question

Discussion in 'Python' started by Gary Robinson, Jul 2, 2003.

  1. In some code we're writing we're making an assumption, and I'd like to
    confirm that the assumption is valid.

    Suppose a signal arrives while a file is being written, and the signal
    handler explicitly raises a SystemExit exception.

    My understanding is that the C-level I/O code will continue and the signal
    won't be processed until the end of the atomic python interpreter
    instruction that invoked that C code.

    Then, the signal handler is executed, including the SystemExit.

    Are we guaranteed that there are no circumstances under which any more file
    I/O will be carried out by the interrupted code after the signal handler is
    invoked? That is, are we guaranteed that the SystemExit raised by the signal
    handler will immediately terminate the interrupted call to write()?

    The answer seems to be "obviously YES" but I need to be sure so I thought it
    was worth asking.

    Thanks--

    --Gary

    --
    Putting http://wecanstopspam.org in your email helps it pass through
    overzealous spam filters.

    Gary Robinson
    CEO
    Transpose, LLC

    207-942-3463
    http://www.transpose.com
    http://radio.weblogs.com/0101454
    Gary Robinson, Jul 2, 2003
    #1
    1. Advertising

  2. Gary Robinson

    Donn Cave Guest

    Quoth Gary Robinson <>:
    | In some code we're writing we're making an assumption, and I'd like to
    | confirm that the assumption is valid.
    |
    | Suppose a signal arrives while a file is being written, and the signal
    | handler explicitly raises a SystemExit exception.
    |
    | My understanding is that the C-level I/O code will continue and the signal
    | won't be processed until the end of the atomic python interpreter
    | instruction that invoked that C code.
    |
    | Then, the signal handler is executed, including the SystemExit.
    |
    | Are we guaranteed that there are no circumstances under which any more file
    | I/O will be carried out by the interrupted code after the signal handler is
    | invoked? That is, are we guaranteed that the SystemExit raised by the signal
    | handler will immediately terminate the interrupted call to write()?

    I can't say I really know the details for sure, but here are a couple
    of questions and observations.

    - What interrupted call to write()? I thought your C I/O call was
    going to complete. I believe that's correct, it will complete,
    if it's really to disk, or if you get BSD-style restartable I/O
    on your platform. If so, the output goes out, even if after the
    delivery of the signal and the execution of the Python-internal
    C signal handler. At the system call level, at any rate, there
    isn't anything to terminate by the time the Python code runs.

    - If writing to a pipe or something and I/O isn't restartable, write
    will raise an exception; don't know for sure when the signal handler's
    Python code will run in this case, presumably before the exception
    handlers but I'm just guessing.

    - But you're probably not really calling posix.write, are you? The
    Python file object uses C stdio functions like fwrite(3). In this
    case, the effect should be similar, but different in a way that you
    may care about, I can't tell. The thing is, C stdio output doesn't
    actually write all the data to disk. The rest typically is written
    on fclose(3), which is automatically done at process exit, whether
    Python closes the file objects or not. In this case, the data is
    still all from writes issued prior to the Python code signal handler,
    but some of it is written to disk afterwards.

    Donn Cave,
    Donn Cave, Jul 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Pronath
    Replies:
    1
    Views:
    1,133
    Diez B. Roggisch
    Jan 3, 2005
  2. Jack Orenstein

    threading.Thread vs. signal.signal

    Jack Orenstein, Sep 18, 2005, in forum: Python
    Replies:
    0
    Views:
    445
    Jack Orenstein
    Sep 18, 2005
  3. Weng Tianxiang
    Replies:
    2
    Views:
    630
    Jonathan Bromley
    Jan 30, 2007
  4. Nicolas Moreau
    Replies:
    9
    Views:
    3,049
  5. Peter
    Replies:
    34
    Views:
    1,904
    James Kanze
    Oct 17, 2009
Loading...

Share This Page