mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #781 from fe-lix-/master
Getting an explicit error message on server creation
This commit is contained in:
commit
c1272bc69d
1 changed files with 12 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
from __future__ import print_function
|
||||
import sys
|
||||
try:
|
||||
import SimpleHTTPServer as srvmod
|
||||
except ImportError:
|
||||
|
|
@ -13,7 +14,16 @@ PORT = 8000
|
|||
|
||||
Handler = srvmod.SimpleHTTPRequestHandler
|
||||
|
||||
httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||
try:
|
||||
httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||
except OSError as e:
|
||||
print("Could not listen on port", PORT)
|
||||
sys.exit(getattr(e, 'exitcode', 1))
|
||||
|
||||
|
||||
print("serving at port", PORT)
|
||||
httpd.serve_forever()
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt as e:
|
||||
print("shutting down server")
|
||||
httpd.socket.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue