1

I'm on OS-X, using the flask library to make a small api.

Usually when I terminate the process with Ctrl-C it used to just raise KeyboardInterrupt, but now it will exit with socket.error: [Errno 48] Address already in use instead. After that, trying to restart the program throws the same error. This used to happen occasionally, but now seems to happen every time. Activity Monitor shows the Python process to still be running with 3 threads.

The fix is to quit the process from Activity Monitor.

Why does the process not get terminated properly anymore (note: I am using Ctrl-C, not Ctrl-Z), and is there a way to fix this minor inconvenience?

Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103
  • Possible duplicate http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program – The2ndSon Aug 04 '14 at 18:46
  • @The2ndSon , this is somewhat separate issue. When you initialize Flask with `threaded=True` parameter and after you press Ctrl+C, application continues to run in processes. The question is, how to stop threaded Flask application entirely without needing to kill the process each time. – Andriy Makukha Jan 10 '18 at 12:58

1 Answers1

0

You probably need SO_REUSEPORT and SO_REUSEADDR socket options set? That error means that you tried to bind a port before the previous binding timed out after a close.

synthesizerpatel
  • 27,321
  • 5
  • 74
  • 91