Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'calls.': 0.07; 'python': 0.09; 'handler,': 0.09; 'ioerror:': 0.09; 'okay': 0.09; 'cc:addr:python-list': 0.10; 'handling.': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'sender:addr:gmail.com': 0.18; 'module': 0.19; 'versions': 0.20; 'cc:2**0': 0.23; 'seems': 0.23; 'cc:no real name:2**0': 0.24; 'feature': 0.24; 'allows': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; '---': 0.26; 'skip:" 20': 0.26; '(most': 0.27; 'am,': 0.27; '2.6': 0.27; 'message-id:@mail.gmail.com': 0.27; 'this?': 0.28; 'received:209.85.212': 0.28; 'attempting': 0.29; 'behavior.': 0.29; 'writes:': 0.29; 'this.': 0.29; 'fri,': 0.30; 'function': 0.30; 'file': 0.32; 'not.': 0.32; 'traceback': 0.33; 'received:google.com': 0.34; 'eric': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'operating': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'header:Received:5': 0.40; 'your': 0.60; '20,': 0.65; 'interrupted': 0.65; 'jul': 0.65; 'middle': 0.66; 'directly.': 0.78; 'interrupt': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=bxmMrWWm4n7s3PhRS5gANO9J2GL4FYCzg3/pqtH2Hwo=; b=sI4RW0ZHMWRwzIfMzYFO8wKUiW0fCIjtqDqbmcr8Ba1fpIuS0pjc4DuppTG0/4m0r2 HGa0RG0rddOwnyMzRAUx2sKUumEneV0+ptrabIQEEM9UJ5BElS6zzy98Z4DDUH0nVL2t dpO1QJ3NZ27nSpB+IvMHRS1hA2e2x/QHgdBYr3d50iaz2+NkmNXj+xhnpuw1GFPJDXHh tq3oqSNg69AkCUIl1iAxTjjgK/Dp59Fm348uElT4WyoAPVI58Wyh0ZrDzgx2tDAqicId +vq8tTks1QbO8j2PO8gH4nGLSqqL3bSTQycLRgT2fzmrbeOF+ge4SDtcMnE50RfKfksp 9EUg== MIME-Version: 1.0 Sender: kushal.kumaran@gmail.com In-Reply-To: <87mx2vrmjh.fsf@handshake.de> References: <87mx2vrmjh.fsf@handshake.de> From: Kushal Kumaran Date: Fri, 20 Jul 2012 14:22:59 +0530 X-Google-Sender-Auth: D2jNxiuqIK9eIFin3q-IOag8O_4 Subject: Re: properly catch SIGTERM To: Dieter Maurer Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342774402 news.xs4all.nl 6957 [2001:888:2000:d::a6]:52895 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25685 On Fri, Jul 20, 2012 at 11:39 AM, Dieter Maurer wrote: > Eric Frederich writes: >> ... >> This seems to work okay but just now I got this while hitting ctrl-c >> It seems to have caught the signal at or in the middle of a call to >> sys.stdout.flush() >> --- Caught SIGTERM; Attempting to quit gracefully --- >> Traceback (most recent call last): >> File "/home/user/test.py", line 125, in >> sys.stdout.flush() >> IOError: [Errno 4] Interrupted system call >> How should I fix this? > > This is normal *nix behavior. Any signal, even if caught by a signal > handler, can interrupt system calls. > > Modern *nix versions might allow to control whether a signal interrupts > a system call or not. Check the signal documentation for your operating > system for the control you have over signal handling. Likely, > you cannot directly control the feature via Python, but the > "ctypes" module allows you to call C functions directly. > The signal.siginterrupt function has been added in python 2.6 to do this. -- regards, kushal