473,395 Members | 1,456 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,395 software developers and data experts.

IOError: [Errno 4] Interrupted system call

Hello,every one, I meet a question:

in my old script, I usually use os.popen2() to get info from standard
unix(LinuX) program like ps,ifconfig...

Now, I write a OO-based programme, I still use os.popen2( check
whether mplayer still working via ps command ), but some things I got
the following message:

Traceback (most recent call last):
File "./mkt.py", line 351, in loop_timeout
self.process(self.event.get_next())
File "./mkt.py", line 361, in process
self.player.play(command[1])
File "./mkt.py", line 107, in play
if self.is_playing():
File "./mkt.py", line 78, in is_playing
info = rfd.readlines()
IOError: [Errno 4] Interrupted system call

why? Thank you!
--
LinuX Power
Feb 7 '07 #1
7 22195
In article <ma***************************************@python. org>,
Marco <ma***@waven.comwrote:
Hello,every one, I meet a question:

in my old script, I usually use os.popen2() to get info from standard
unix(LinuX) program like ps,ifconfig...

Now, I write a OO-based programme, I still use os.popen2( check
whether mplayer still working via ps command ), but some things I got
the following message:

Traceback (most recent call last):
File "./mkt.py", line 351, in loop_timeout
self.process(self.event.get_next())
File "./mkt.py", line 361, in process
self.player.play(command[1])
File "./mkt.py", line 107, in play
if self.is_playing():
File "./mkt.py", line 78, in is_playing
info = rfd.readlines()
IOError: [Errno 4] Interrupted system call

why? Thank you!
Some signal was evidently delivered to your process, while
you had a "slow" read in progress (i.e., not from disk.)
The read was interrupted to deliver the signal.

Look for signal handlers in your code and any library functions
you call. I hope library functions don't have signal handlers,
sounds like a horrible idea to me. If your code has a signal
handler for SIGCHLD, try to get rid of that - the handler itself
is causing your problem.

OO (Object Oriented?) doesn't have anything to do with the problem,
that I can think of.

Donn Cave, do**@u.washington.edu
Feb 7 '07 #2
i'm getting the same error when trying to read results from popen2
within a pyQt window. is this a threading issue? is my pyQt window
responsible for interrupting the read? i'm fairly new to python so
i'm struggling to figure this out. can you recommend any possible
methods of preventing this? for instance, could acquiring a thread
lock before calling popen solve the problem?

thanks,
chad

Feb 16 '07 #3
En Thu, 15 Feb 2007 23:57:29 -0300, <ch*****@gmail.comescribió:
i'm getting the same error when trying to read results from popen2
within a pyQt window. is this a threading issue? is my pyQt window
responsible for interrupting the read? i'm fairly new to python so
i'm struggling to figure this out. can you recommend any possible
methods of preventing this? for instance, could acquiring a thread
lock before calling popen solve the problem?
I dont know pyQt but in general, blocking operations (like a syncronous
read) can return EINTR when a signal arrives in the middle. Just retrying
the operation would be enough; by example, if you have a read() inside a
loop, just ignore the exception and continue.

--
Gabriel Genellina

Feb 16 '07 #4
In article <11**********************@l53g2000cwa.googlegroups .com>,
ch*****@gmail.com wrote:
i'm getting the same error when trying to read results from popen2
within a pyQt window. is this a threading issue? is my pyQt window
responsible for interrupting the read? i'm fairly new to python so
i'm struggling to figure this out. can you recommend any possible
methods of preventing this? for instance, could acquiring a thread
lock before calling popen solve the problem?
No.

Did you look at the text of the post you responded to here?
What do you think about that advice? Do you have any
signal handlers?

Donn Cave, do**@u.washington.edu
Feb 16 '07 #5
i don't have any signal handlers in my code, but i have no idea what
is going on in the internals of the pyQt framework that i'm using for
the GUI.

as far as simply ignoring the exception, that does not seem to work.
for instance, here's some code i've tried:
p = subprocess.Popen('mycommand', shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, close_fds=True)
output = ''
tries = 0
while tries < 12:
try:
tries = tries+1
print "retrieving results"
output = p.stdout.readlines()

except IOError:
print "IOError! try %s" % tries
print "output:", output
#time.sleep(1)
else:
print "Great Success"
print "output:", output
break
--printout: successful run--
retrieving results
Great Success
output: []

--printout: IOError run--
retrieving results
IOError! try 1
output:
retrieving results
Great Success
output: []

if the first try raises an error output does not get set and then the
second try succeeds but returns an empty list when it should return
results. moving the Popen inside the loop isn't an option either,
because, in addition to returning results, the command performs an
action which should only run once.

sorry if i'm missing something obvious here, i'm a python newb.

-chad


Feb 16 '07 #6
In article <11**********************@k78g2000cwa.googlegroups .com>,
ch*****@gmail.com wrote:
i don't have any signal handlers in my code, but i have no idea what
is going on in the internals of the pyQt framework that i'm using for
the GUI.

as far as simply ignoring the exception, that does not seem to work.
for instance, here's some code i've tried:
p = subprocess.Popen('mycommand', shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, close_fds=True)
output = ''
tries = 0
while tries < 12:
try:
tries = tries+1
print "retrieving results"
output = p.stdout.readlines()

except IOError:
print "IOError! try %s" % tries
print "output:", output
#time.sleep(1)
else:
print "Great Success"
print "output:", output
break
....
if the first try raises an error output does not get set and then the
second try succeeds but returns an empty list when it should return
results. moving the Popen inside the loop isn't an option either,
because, in addition to returning results, the command performs an
action which should only run once.

sorry if i'm missing something obvious here, i'm a python newb.
No, actually this is somewhat non-obvious, if I'm right.

You can't use readlines() like that, it's a Python
thing that evidently loses some or all of its buffered
data, and you start over from scratch.

Instead, probably the simplest thing would be to implement
your own readlines around that restart loop, actually reading
one line at a time and appending to the line list. I'm not
sure that's totally bulletproof - probably will work, but
if you need a sure thing, I would go to UNIX I/O (posix.read),
in a loop, and then split the concatenated results by newline.

Or, of course if you could shut down the signals...

Donn Cave, do**@u.washington.edu
Feb 17 '07 #7
En Fri, 16 Feb 2007 18:07:40 -0300, <ch*****@gmail.comescribió:
i don't have any signal handlers in my code, but i have no idea what
is going on in the internals of the pyQt framework that i'm using for
the GUI.

p = subprocess.Popen('mycommand', shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, close_fds=True)
output = p.stdout.readlines()
There is a problem using a high-level approach like readlines(): *either*
there is no exception, and you get all the output, *or* there is an
exception and you get nothing. readlines() can't return a partial result
*and* raise an exception at the same time. (Perhaps EINTR should be a
special case, but currently it's converted into an IOError like all other
error codes).

You could read one character at a time with read(1) (to minimize the risk
of data loss), or simply use a temporary file: "mycomand >temporary" and
then read its contents. This appears to be the safest way.

--
Gabriel Genellina

Feb 17 '07 #8

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

Similar topics

2
by: Jakub Moscicki | last post by:
Hello, A small problem: I get a signal during a system call (from xmlrpclib -> httplib) and an exception "IOError: Interrupted system call" is raised (this is system dependant, on other machine...
0
by: Sylwia | last post by:
Hi! I have implemented a Python services. It behaves as a supervisor for log files. If the space used by log files is bigger than a given upper limit, then it starts to delete log files until...
2
by: Sylwia | last post by:
Hi! I need your help... I have the following problem. I've implemented the python Windows Service which behaves like a log supervisor. If the space used by log files is bigger than a given...
0
by: Nazgul | last post by:
Hi! Sorry if I posted it twice... I need your help... I have the following problem. I've implemented the python Windows Service which behaves like a log supervisor. If the space used by log...
2
by: Nigel King | last post by:
I have a problem with the logging module. It reports a Broken Pipe error after outputing to the log file occasionally (5%). This does not appear to happen on Mac OSX using current finked python...
0
by: nicogrubert | last post by:
Hi there I am trying to read the content of a really large text file (1GByte) and I get the following exception if I try to call readlines() on the opened textfile: IOError: Cannot allocate...
0
by: Marco | last post by:
Hello,every one, I meet a question: in my old script, I usually use os.popen2() to get info from standard unix(LinuX) program like ps,ifconfig... Now, I write a OO-based programme, I still use...
1
by: ashish | last post by:
Hi All, I wanted to know how to handle events like 'logoff' in the main thread so that any process which is being run by svcDoRun method of service does not get 'interrupted function call'...
2
by: Gilles Ganault | last post by:
Hello I'm trying to use urllib to download web pages with the GET method, but Python 2.5.1 on Windows turns the URL into something funny: ======== url = "amazon.fr/search/index.php?url=search"
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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.