IOError: [Errno 4] Interrupted system call

Donn Cave donn at u.washington.edu
Fri Feb 16 19:31:17 EST 2007


In article <1171660060.302688.101070 at k78g2000cwa.googlegroups.com>,
 chadrik at 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, donn at u.washington.edu



More information about the Python-list mailing list