Python Socket.error Interrupted System Call
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have errno 4 interrupted system call Meta Discuss the workings and policies of this site About Us
Python Eintr
Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with python socket interrupted system call us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just
Python Signal
like you, helping each other. Join them; it only takes a minute: Sign up Catching / blocking SIGINT during system call up vote 7 down vote favorite 2 I've written a web crawler that I'd like to be able to stop via the keyboard. I don't want the program to die when I interrupt it; it needs to flush its data to disk first. I also don't want to catch KeyboardInterruptedException, because the persistent data could be in an inconsistent state. My current solution is to define a signal handler that catches SIGINT and sets a flag; each iteration of the main loop checks this flag before processing the next url. However, I've found that if the system happens to be executing socket.recv() when I send the interrupt, I get this: ^C Interrupted; stopping... // indicates my interrupt handler ran Traceback (most recent call last): File "crawler_test.py", line 154, in
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up What is the proper way to handle (in python) IOError: [Errno http://stackoverflow.com/questions/3016369/catching-blocking-sigint-during-system-call 4] Interrupted system call, raised by multiprocessing.Queue.get up vote 9 down vote favorite When I use multiprocessing.Queue.get I sometimes get an exception due to EINTR. I know definitely that sometimes this happens for no good reason (I open another pane in a tmux buffr), and in such a case I would want to continue working and retry the operation. I can imagine that in some other cases The http://stackoverflow.com/questions/14136195/what-is-the-proper-way-to-handle-in-python-ioerror-errno-4-interrupted-syst error would be due to a good reason and I should stop running or fix some error. How can I distinguish the two? Thanks in advance python error-handling queue multiprocessing ioerror share|improve this question asked Jan 3 '13 at 9:36 Shwouchk 9028 you should make sure the queue is not empty before get: if not queue.empty(): queue.get() –Inbar Rose Jan 3 '13 at 9:39 I believe that if the queue is empty, it will just block the call. Won't it? In any I don't think this is the cause of the error. –Shwouchk Jan 3 '13 at 10:26 add a comment| 2 Answers 2 active oldest votes up vote 11 down vote accepted The EINTR error can be returned from many system calls when the application receives a signal while waiting for other input. Typically these signals can be quite benign and already handled by Python, but the underlying system call still ends up being interrupted. When doing C/C++ coding this is one reason why you can't entirely rely on functions like sleep(). The Python libraries sometimes handle this error code internally, but obviously in this case they're not. You might be interested to read this thread which discusses
User List Committer List Help Tracker Documentation Tracker Development Report Tracker Problem Issue9867 classification Title: Interrupted system calls are not retried Type: behavior Stage: Components: Interpreter Core Versions: https://bugs.python.org/issue9867 Python 2.7 process Status: closed Resolution: duplicate Dependencies: Superseder: file readline, readlines & readall methods can lose data on EINTR View: 12268 Assigned To: Nosy List: DasIch, Trundle, aronacher, benjamin.peterson, exarkun, loewis, ned.deily, pitrou, ronaldoussoren, stutzbach Priority: normal Keywords: Created on 2010-09-16 02:02 by aronacher, last changed 2012-07-12 21:36 by pitrou. This issue is now closed. Messages (20) msg116504 interrupted system - (view) Author: Armin Ronacher (aronacher) * Date: 2010-09-16 02:02 Currently Python does not check fread and other IO calls for EINTR. This usually is not an issue, but on OS X a continued program will be sent an SIGCONT signal which causes fread to be interrupted. Testcase: mitsuhiko@nausicaa:~$ python2.7 Python 2.7 (r27:82508, Jul 3 2010, 21:12:11) [GCC 4.0.1 (Apple interrupted system call Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from signal import SIGCONT, signal >>> def show_signal(*args): ... print 'Got SIGCONT' ... >>> signal(SIGCONT, show_signal) 0 >>> import sys >>> sys.stdin.read() ^Z [1]+ Stopped python2.7 mitsuhiko@nausicaa:~$ fg python2.7 Got SIGCONT Traceback (most recent call last): File "