I'm trying to launch a simple server from a Python script:
server = Popen(['python' ,'-m', 'SimpleHTTPServer', '9090'], stderr=STDOUT, stdout=PIPE)
output = server.communicate()[0] # <- DEBUG
Reading the output, I see:
'/usr/bin/python: Import by filename is not supported.'
What's the problem? How to solve it?
Shawn Chin
87.4k20 gold badges168 silver badges193 bronze badges
asked Jun 1, 2012 at 12:56
pistacchio
59.3k110 gold badges289 silver badges436 bronze badges
1 Answer 1
I suggest change to code to this:
import SimpleHTTPServer
import SocketServer
PORT = 9090
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
answered Dec 21, 2018 at 7:50
user10819040
Sign up to request clarification or add additional context in comments.
1 Comment
tripleee
This has the decided disadvantage that the script cannot perform other tasks while the server runs in the background.
lang-py
subprocessinto your current namespace.sys.executableinstead of'python'.