Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Script hangs
-
This piece of code hangs after running it:
<code>
import webbrowser
from BaseHTTPServer import BaseHTTPRequestHandler
from BaseHTTPServer import HTTPServerclass RequestHandler(BaseHTTPRequestHandler):
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)
server.serve_forever()
</code>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:
<code>
server = HTTPServer(('', 8001), RequestHandler)
webbrowser.open('http://localhost:8001', stop_when_done = True)
</code>
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?