omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    1
    2
    2043
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Alex210
      Alex210 last edited by

      This piece of code hangs after running it:
      <code>
      import webbrowser
      from BaseHTTPServer import BaseHTTPRequestHandler
      from BaseHTTPServer import HTTPServer

      class 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?

      1 Reply Last reply Reply Quote 0
      • Alex210
        Alex210 last edited by

        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?

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Powered by NodeBB Forums | Contributors