473,804 Members | 3,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ignoring SIGPIPE in a python script?


I have a python script that sometimes gets a SIGPIPE signal, and errors
out. And I want it to just terminate as though it had hit EOF.

I'm running:

signal.signal(s ignal.SIGPIPE,s ignal.SIG_IGN)

....in the main function, but the script is still erroring out on sigpipe
when the consumer to its producer terminates early.

Am I going to have to code in a handful of exceptions, and then
conditionalize what happens in those exception handlers, to get the
desired behavior?

ISTR hearing that although bash notifies one of SIGPIPE errors, tcsh
generally silently ignores them. From this, I conclude that it might be
reasonable for my script to ignore SIGPIPE.

Thanks!

Jul 19 '05 #1
1 4225
In article <pa************ *************** *@dcs.nac.uci.e du>,
Dan Stromberg <st******@dcs.n ac.uci.edu> wrote:
I have a python script that sometimes gets a SIGPIPE signal, and errors
out. And I want it to just terminate as though it had hit EOF.

I'm running:

signal.signal(s ignal.SIGPIPE,s ignal.SIG_IGN)

...in the main function, but the script is still erroring out on sigpipe
when the consumer to its producer terminates early.

Am I going to have to code in a handful of exceptions, and then
conditionalize what happens in those exception handlers, to get the
desired behavior?

ISTR hearing that although bash notifies one of SIGPIPE errors, tcsh
generally silently ignores them. From this, I conclude that it might be
reasonable for my script to ignore SIGPIPE.


This is a little idiosyncracy of Python's. You can restore
the default signal handler,
signal.signal(s ignal.SIGPIPE, signal.SIG_DFL)

and it will behave like a normal UNIX application. These other
applications aren't precisely ignoring SIGPIPE, though. If you
think about what that would look like, I guess it would mean they
would continue to write output, since it's truly a rare application
that checks its output (especially since it's usually buffered.)
The SIGPIPE signal just aborts the program. Not really very
much like EOF at all.

You could install your own handler, but it would probably make
about as much sense to just trap the exception.

Donn Cave, do**@u.washingt on.edu
Jul 19 '05 #2

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

Similar topics

28
4621
by: Erik Johnson | last post by:
This is somewhat a NEWBIE question... My company maintains a small RDBS driven website. We currently generate HTML using PHP. I've hacked a bit in Python, and generally think it is a rather cool language. I've done Perl and like it, there are a few features of PHP I like but overall am not too excited about it. I have found PHP's strtotime() function to be quite flexible and handy and we make liberal use of it. I have not yet really...
2
4903
by: DeepBleu | last post by:
When one is using an HTML form via a web broswer, the user submits the form contents and these are passed to a CGI Python script on the web server. I need to write a client script that connects to a web site, runs a Python CGI script on the web server AND passes a string to the CGI Python script that the Python CGI script can store/manipulate/evalute etc.... I know how to connect to the web site and run the CGI Python script using a client...
52
3781
by: Olivier Scalbert | last post by:
Hello , What is the python way of doing this : perl -pi -e 's/string1/string2/' file ? Thanks Olivier
4
3276
by: Tom Purl | last post by:
I just wrote a Python script that is going to be called from bash script. If the Python script fails, I want the bash script to also stop running. Unfortunately, I can't seem to get that to work. Here's the script so far: # custom python script /usr/bin/python /home/username/Dev/Python/packZODB.py \ -s"gsgmc.sigma.zettai.net" -b 7 # next program
0
1265
by: Jack Orenstein | last post by:
I'm using Python 2.2 on RH9. I have a set of Python modules organized into a root package and one other package named foobar. setup.py looks like this: from distutils.core import setup setup( name = 'foobar', version = '0.3', description = 'Foo Bar',
17
3878
by: Paul Rubin | last post by:
Dumb question from a Windows ignoramus: I find myself needing to write a Python app (call it myapp.py) that uses tkinter, which as it happens has to be used under (ugh) Windows. That's Windows XP if it makes any difference. I put a shortcut to myapp.py on the desktop and it shows up as a little green snake icon, which is really cool and Pythonic. When I double click the icon, the app launches just fine and the tkinter interface does...
9
2084
by: TPJ | last post by:
First I have to admit that my English isn't good enough. I'm still studying and sometimes I just can't express what I want to express. A few weeks ago I've written 'Python Builder' - a bash script that allows anyone to download, compile (with flags given by user) and install Python and some external modules (e.g. wxPython, PyGTK, Numeric...). I use Python every day and when new version of Python (or some external module) is released, I...
6
9952
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
0
1131
by: mrafi | last post by:
Hey All, I am working with numpy I have a data set with a lot of nan values, and i want to calculate standard deviation is there a direct function to do it for example nansum(or something like this), to calculate standard deviation ignoring nan values?? Thanks Rafi --
0
9704
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
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
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...
1
10303
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9132
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...
0
6845
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
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2978
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.