This piece of code hangs after running it:
from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServer
def do_GET(self): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() self.wfile.write('<body><h2>hello</h2></body>')
if name == 'main':
server = HTTPServer(('', 80), RequestHandler)
webbrowser.open('http://localhost', stop_when_done = True)
Pythonista keeps displaying the stop button (instead of play) even after tapping "done". I can't run this script again (or any other script) until completely quitting and restarting Pythonista. What could be the problem and what can I do?
Changing the port helps:
server = HTTPServer(('', 8001), RequestHandler)
webbrowser.open('http://localhost:8001', stop_when_done = True)
This works as I expected: "Done" closes the browser and the server exits. No restart needed.
Weird: When I omit the stop_when_done parameter, it works with port 80 but hangs with port 8001?! In all cases browser and server start and run fine, only sometimes the server won't quit, "stop" button not working. So it probably has nothing to do with privileged ports, right?
I'm lost here, can't explain that. Any ideas? I'm an absolute beginner in Python, so am I maybe missing something obvious? E.g. is this behaviour perfectly normal and to be expected from Python?