Reputation: 328
I accidentally hit ctrl z instead of ctrl c to stop python SimpleHTTPServer and it came up saying
[1] + 35296 suspended python -m SimpleHTTPServer
now I cannot restart it on the same port as port 8000 is in use
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleHTTPServer.py", line 220, in <module>
test()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleHTTPServer.py", line 216, in test
BaseHTTPServer.test(HandlerClass, ServerClass)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 595, in test
httpd = ServerClass(server_address, HandlerClass)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 419, in __init__
self.server_bind()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 48] Address already in use
How can I stop this process so that I can use port 8000 again?
Thanks
Upvotes: 0
Views: 1566
Reputation: 3943
The process is suspended in the background, you'll have to kill it for it to release the port.
If you're in the same terminal, running fg
will bring it to the front and reactivate it, letting you interrupt it normally with CTRL+C.
If you're not, you can use that number that got printed (the process ID, or PID) to kill it, but you'll first have to reactivate it, so that it can react:
kill -CONT 35296
kill 35296
Upvotes: 4
Reputation: 921
use fg
to bring it to the foreground, and then you can kiil it using ctrl+c
Upvotes: 1