Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #96290
| From | "James Harris" <james.harris.1@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Signal SIGINT ignored during socket.accept |
| Date | 2015-09-10 20:11 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <msskh1$j00$1@dont-email.me> (permalink) |
| References | <msshpm$7pn$1@dont-email.me> <mailman.332.1441910212.8327.python-list@python.org> |
"Chris Angelico" <rosuav@gmail.com> wrote in message
news:mailman.332.1441910212.8327.python-list@python.org...
> On Fri, Sep 11, 2015 at 4:24 AM, James Harris
> <james.harris.1@gmail.com> 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?
Good point. It turns out that it does matter. I have one implementation
which fails (Windows) and one which works (Linux). The Linux one breaks
out on Control-C. The Windows one does not recognise Control-C until the
accept() call returns.
The implementations are:
$ uname -srm
Linux 3.18.7-v7+ armv7l
$ python -V
Python 2.7.3
And
c:\>ver
Microsoft Windows XP [Version 5.1.2600]
c:\>python -V
Python 2.7.9
> Have you tested on any Unix system? I just tried on my Linux, and
> Ctrl-C interrupted the accept() straight away,
Thanks.
> so this is quite probably a Windows-only issue.
That turns out to be exactly right.
> Can you produce an absolute minimal demo program? I'd try something
> like this:
>
> import socket
> s = socket.socket()
> s.listen(1)
> s.accept()
Yes:
port = 8880
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", port))
s.listen(1)
endpoint = s.accept()
> which is what worked for me (interactively, Python 2.7.9 and 3.6.0a0,
> Debian Linux).
On Linux I get
$ python socktest.py
^CTraceback (most recent call last):
File "socktest.py", line 6, in <module>
endpoint = s.accept()
File "/usr/lib/python2.7/socket.py", line 202, in accept
sock, addr = self._sock.accept()
KeyboardInterrupt
$
On Windows I get
S:\>python socktest.py
Traceback (most recent call last):
File "socktest.py", line 6, in <module>
endpoint = s.accept()
File "C:\Python27\lib\socket.py", line 202, in accept
sock, addr = self._sock.accept()
KeyboardInterrupt
S:\>
However, on Windows the recognition of Control-C does not happen until
after something connects to the socket.
I will carry on researching it but maybe the above gives a clue to those
in the know...!
James
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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