简体   繁体   中英

python SimpleHTTPServer suspended, how to stop?

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

Kill the process.

kill 35296 

or:

kill %1

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

使用fg将其带到前台,然后可以使用ctrl + c锁定它

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM