Path: csiph.com!goblin2!goblin.stu.neva.ru!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:skip:s 10': 0.05; 'socket': 0.07; 'cc:addr:python-list': 0.09; 'underlying': 0.09; 'python': 0.10; 'python.': 0.11; 'accept()': 0.16; 'control-c': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'linux).': 0.16; 'pressed': 0.16; 'program?': 0.16; 'recognised': 0.16; 's.accept()': 0.16; 'socket.': 0.16; 'wrote:': 0.16; 'linux,': 0.18; '(in': 0.18; 'windows': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'issue.': 0.20; 'libraries': 0.22; 'sep': 0.22; 'am,': 0.23; 'absolute': 0.23; 'this:': 0.23; 'tried': 0.24; 'import': 0.24; 'unix': 0.24; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'connects': 0.27; 'follows': 0.29; 'socket,': 0.29; 'system?': 0.29; 'too.': 0.30; 'call.': 0.30; 'minimal': 0.30; 'posts': 0.30; "i'd": 0.31; 'probably': 0.31; 'run': 0.33; 'problem': 0.33; 'common': 0.33; 'worked': 0.34; 'received:google.com': 0.35; 'question,': 0.35; 'quite': 0.35; 'something': 0.35; 'but': 0.36; 'subject:: ': 0.37; 'version': 0.38; 'interrupted': 0.76; 'away,': 0.84; 'chrisa': 0.84; 'seen.': 0.84; 'to:none': 0.91; 'relate': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=BMtvR/fzXm6oIrM1w15KFhYvKu+gjKJ3PPx604uoUrs=; b=edNvGGeuDigV/owxSNM+/l4KB9edY7WNkCRLg3pexGx8egIQB50GazbskU+Ujq5pN5 5TjEzyYtxeuHSbPSyRuOZ6fkxZVjZoxmNvawuaqg9GOq7/vMgs/Sku8EjRXghUiJeB8S S6yOEnkuyMlF9Dgh5sWLqClj6YxG3cyqxAJVIwiVIOZV7GVqvLfsqr/XhIMGeCbwKiSM l+Hl0NeYvDyBJjEclwCXOkAMhdaSYl10ipR1m9dUovNsmHqZGJUvh0G2Q1M/90V3BeVJ BU+ENx5nbFCBZhROOQaomVgSg3p8+1X1vEi1i7QTO5Je8TtC+b/yn+WFCsfXJo2bxxRD 2fdQ== MIME-Version: 1.0 X-Received: by 10.50.114.100 with SMTP id jf4mr9192726igb.94.1441910203472; Thu, 10 Sep 2015 11:36:43 -0700 (PDT) In-Reply-To: References: Date: Fri, 11 Sep 2015 04:36:43 +1000 Subject: Re: Signal SIGINT ignored during socket.accept From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1441910212 news.xs4all.nl 23791 [2001:888:2000:d::a6]:47927 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:96284 On Fri, Sep 11, 2015 at 4:24 AM, James Harris wrote: > I have a listening socket, self.lsock, which is used in an accept() call as > follows > > endpoint = self.lsock.accept() > > The problem is that if control-C is pressed it is not recognised until > something connects to that socket. Only when the accept() call returns is > the signal seen. > > The question, then, is how to get the signal to break out of the accept() > call. This is currently on Windows but I would like it to run on Unix too. I > see from the web that this type of thing is a common problem with the > underlying C libraries but I cannot quite relate the posts I have found to > Python. What version of Python are you using? Also (in case it matters), what version of Windows? Have you tested on any Unix system? I just tried on my Linux, and Ctrl-C interrupted the accept() straight away, so this is quite probably a Windows-only issue. Can you produce an absolute minimal demo program? I'd try something like this: import socket s = socket.socket() s.listen(1) s.accept() which is what worked for me (interactively, Python 2.7.9 and 3.6.0a0, Debian Linux). ChrisA