FAQ

On Fri, Sep 11, 2015 at 5:11 AM, James Harris wrote:
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...!

This is a known problem on Windows. I can't remember what the best
solution was, but there's a chance something got into 2.7.10, as it
was fairly recent. There's a significantly better chance that
something's different in Python 3.x. You may find it worth grabbing a
few different versions of Python and trying the same code on all of
them.


You may run into issues with XP, though. For instance, Python 3.5
doesn't support it, and (IIRC) won't install at all; 3.4 does work, as
will all releases of 2.7.x. Worst case, grab yourself a Windows 7 and
try a few tests.


But a quick test on one of my VMs, with 3.4 on Win 7, didn't show any
change. 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).


Of course, switching over to Unix is also a good option...


ChrisA

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 11 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedSep 10, '15 at 6:24p
activeSep 11, '15 at 11:15p
posts11
users4
websitepython.org

People

Translate

site design / logo © 2017 Grokbase