Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python socket accept in the main thread prevents quitting

I'm playing around with sockets in python, just for the purpose of learning about them. However I am really annoyed with the following problem:

import socket
soc = socket.socket(socket.AF_INET)
soc.bind(('localhost',8000))
soc.listen(0)
client = soc.accept()

While the socket is waiting for a connection, pressing ctrl-c does not quit the application.

How can I quit the application?

A similar issue was addressed in these two questions, but there the accept method was called from a separate thread and the problem was how to make ctrl-c kill that thread. Here the accept method is called from the main thread.

Edit: I am running python 3.3.0 on Win7 64 bit.

like image 558
Joe Avatar asked Sep 06 '26 05:09

Joe


1 Answers

You should use CTRL + Break. That should kill it.

like image 181
ATOzTOA Avatar answered Sep 07 '26 19:09

ATOzTOA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!