Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96299

Re: Signal SIGINT ignored during socket.accept

From "James Harris" <james.harris.1@gmail.com>
Newsgroups comp.lang.python
Subject Re: Signal SIGINT ignored during socket.accept
Date 2015-09-10 21:12 +0100
Organization A noiseless patient Spider
Message-ID <msso49$28e$1@dont-email.me> (permalink)
References <msshpm$7pn$1@dont-email.me> <mailman.332.1441910212.8327.python-list@python.org> <msskh1$j00$1@dont-email.me> <mailman.337.1441913195.8327.python-list@python.org>

Show all headers | View raw


"Chris Angelico" <rosuav@gmail.com> wrote in message 
news:mailman.337.1441913195.8327.python-list@python.org...
> On Fri, Sep 11, 2015 at 5:11 AM, James Harris 
> <james.harris.1@gmail.com> wrote:

...

>> However, on Windows the recognition of Control-C does not happen 
>> until after
>> something connects to the socket.

...

> This is a known problem on Windows.

...

> It's entirely possible that a blocking socket-accept call will
> continue to block. There is one rather silly option, and that's to use
> select() to effectively poll for Ctrl-C... or, possibly better, have a
> separate program that shuts down your server (by connecting to it,
> which thus breaks the stranglehold).

Thanks for your help, Chris. Using select() is a very good option. I 
tried first without a timeout and even then this version of Windows does 
not recognise Control-C until after the select() call returns (which 
needs similar prompting as with the accept() call. However, select() 
with a timeout allows the code to work both on Windows and Linux. 
Hooray!

For anyone else who is looking for this the earlier test code was 
changed to

port = 8880
import select
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(0)
s.bind(("", port))
s.listen(1)
while 1:
  ready = select.select((s,), (), (), 0.5)
  #print '(ready %s)' % repr(ready)
  if (ready[0]):
    try:
      endpoint = s.accept()
    except socket.error, details:
      print 'Ignoring socket error:', repr(details)
      continue
    print '(endpoint %s)' % repr(endpoint)
    if endpoint:
      break

James

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Signal SIGINT ignored during socket.accept "James Harris" <james.harris.1@gmail.com> - 2015-09-10 19:24 +0100
  Re: Signal SIGINT ignored during socket.accept Chris Angelico <rosuav@gmail.com> - 2015-09-11 04:36 +1000
    Re: Signal SIGINT ignored during socket.accept "James Harris" <james.harris.1@gmail.com> - 2015-09-10 20:11 +0100
      Re: Signal SIGINT ignored during socket.accept Chris Angelico <rosuav@gmail.com> - 2015-09-11 05:26 +1000
        Re: Signal SIGINT ignored during socket.accept "James Harris" <james.harris.1@gmail.com> - 2015-09-10 21:12 +0100
          Re: Signal SIGINT ignored during socket.accept Chris Angelico <rosuav@gmail.com> - 2015-09-11 12:01 +1000
            Re: Signal SIGINT ignored during socket.accept Grant Edwards <invalid@invalid.invalid> - 2015-09-11 13:50 +0000
              Re: Signal SIGINT ignored during socket.accept Marko Rauhamaa <marko@pacujo.net> - 2015-09-11 17:00 +0300
              Re: Signal SIGINT ignored during socket.accept Chris Angelico <rosuav@gmail.com> - 2015-09-12 00:27 +1000
              Re: Signal SIGINT ignored during socket.accept "James Harris" <james.harris.1@gmail.com> - 2015-09-11 18:14 +0100
                Re: Signal SIGINT ignored during socket.accept "James Harris" <james.harris.1@gmail.com> - 2015-09-12 00:15 +0100

csiph-web