473,796 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 18 '05 #1
2 3968
Quoth Gary Robinson <gr*******@tran spose.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.co m
Jul 18 '05 #2
Quoth Gary Robinson <gr*******@tran spose.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.co m
Jul 18 '05 #3

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

Similar topics

5
2302
by: Klaus Neuner | last post by:
Hello, consider the following two programs: # (1) import sys, signal def alarm_handler(signum, frame): raise
1
2877
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 http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html#tag_02_04_03 The reason is, that if a signal is caught while your program is in the malloc routine, and the signal handler calls malloc or free again, then the heap will be corrupted, probably...
4
3906
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 much. Thanks, Ahmed Ossman
3
3526
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.*/ signal(SIGINT,crash); signal(SIGBUS,crash); signal(SIGSEGV,crash); This part works. Those signals cause the "crash.c" module to run and get rid of the lock. Is there a standard way to also print
4
2018
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 know Unixes do it, but what about windows ? does it implements all SIG* signal promptly ? Thanks ! -Eric Boutin
7
1701
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 every input of j as zero. Once we give the value of both i and j as non-zero, it displays i/j and terminates. This is the sample code i tried: #include <signal.h> void sig_s(int signo);
2
6022
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 language syntax itself. Thank you!
18
3926
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 the time when the program was started the first time. My platform is a DEC machine with Tru64 onboard. A possible explanation could be, that the time() function is called
2
2864
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 second is "frame"? What is "frame", please? Thank you!
5
6651
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 another program that executes it as a child process using popen2.Popen4(). I was attempting to use signals to stop it (using os.kill()) but I keep running into a problem where sending the signal causes an infinite loop of printing the message...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10018
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.