473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Signal-handling question

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
gr*******@transpose.com
207-942-3463
http://www.transpose.com
http://radio.weblogs.com/0101454

Jul 18 '05 #1
2 3937
Quoth Gary Robinson <gr*******@transpose.com>:
| 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, do**@drizzle.com
Jul 18 '05 #2
Quoth Gary Robinson <gr*******@transpose.com>:
| 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, do**@drizzle.com
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Klaus Neuner | last post by:
Hello, consider the following two programs: # (1) import sys, signal def alarm_handler(signum, frame): raise
1
by: Michael Pronath | last post by:
Hi, can I make sure that Python uses only async-signal safe glibc functions in signal handlers? For example, you must not call malloc or free in signal handlers, see...
4
by: Ahmed Ossman | last post by:
hi, I want to save the return value from the signal() function, what is the type of the variable. i.e. I want to do the following: <variable type?> ret_sig = signal(......); I need it soo...
3
by: Martin McCormick | last post by:
A C program contains several signal statements to remove a lock file if the program gets killed: /*Set up interrupt handler to catch ctrl-C so that lock file can be removed.*/...
4
by: Eric Boutin | last post by:
Hi ! currently reading C docs, I think I'm reading docs about the stdc lib, but I'm not shure.. it talks about signals, does *all* OS implement the signal function, and use it well ? I mean.. I...
7
by: Amit Sharma | last post by:
Hi, I want to write a program, where until we give the value of j as non zero, it should go on asking us values of i and j, displaying the message "Division by zero: Floating point exception" for...
2
by: None | last post by:
Hello, 1. The prototype of function signal in signal.h: void (*signal(int sig, void (*func)(int)))(int); is some complex to me. Would you please explain it to me in detail with the C...
18
by: Sven | last post by:
Hi, I found a strange behaviour when using the time() function from time.h. Sometimes when it is called, it does not show the correct time in seconds, but an initial value. This time seem to be...
2
by: Marco | last post by:
Hi, In C, a signal handler function has only one parameter, that is signal number. But in Python(import signal), a signal handler function has two parameters, the first is signal number, the...
5
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.