0

When I run this script from my windows10 terminal:

import time

try:
   while True:
      time.sleep(1)
      print('still alive')
except KeyboardInterrupt:
   print('Keyboard interruption. Goodbye')

and press ctrl-c : keyboard interruptpion is activate and the process ends

but when I run this script:

import socket

try:
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
        s.bind(('127.0.0.1', 65432))        
        s.listen()
        conn, addr = s.accept()        
except KeyboardInterrupt:
    print('Keyboard interruption. Goodbye')

then crtl-c doesn't work and I need to find another way to shutdown my process. Why is that?

GyRo
  • 2,586
  • 5
  • 30
  • 38
  • 1
    Does this answer your question? [Python socket accept in the main thread prevents quitting](https://stackoverflow.com/questions/15189888/python-socket-accept-in-the-main-thread-prevents-quitting) – SuperStormer Jun 11 '22 at 09:03
  • @SuperStormer, you are right my question is a duplication of the link you sent. But no, none of the suggestion there helped me. Very strange behavior of Windows or pyhton 3.7 on Windows – GyRo Jun 11 '22 at 09:23

0 Answers0