How to close a socket left open by a killed program?
Assume your socket is named s
... you need to set socket.SO_REUSEADDR
on the server's socket before binding to an interface... this will allow you to immediately restart a TCP server...
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((ADDR, PORT))
How to close sockets left open by a killed program?
According to;
https://superuser.com/questions/127863/manually-closing-a-port-from-commandline
Only an application can close the sockets it is using, after the applications process is killed, the sockets should be automatically freed within a couple of minutes. Are you being patient enough?
Socket remains open after program has closed (C++)
http://hea-www.harvard.edu/~fine/Tech/addrinuse.html should answer a lot of your questions. I tend to use SO_REUSEADDR to work around that problem.
Related Topics
Get Last N Lines of a File, Similar to Tail
Python Gdal 2.1 Installation on Ubuntu 16.04
How to Install Python on Alpine Linux
/Usr/Bin/Ld: Cannot Find -Lpython2.7
Send Sigint in Python to Os.System
Python Parsing Log File to Extract Events in Real Time
How to Package a Python Daemon with Setuptools
How to Pass a List Variable to Subprocess.Call Command in Python
How to Crop an Image in Opencv Using Python
Extracting Data from HTML Table
Simulate Mouse Clicks on Python
How to Control the Keyboard and Mouse with Python
How to Determine Pid of Process Started via Os.System
How Would a Python Script Running on Linux Call a Routine in a Python Script Running Under Wine