Antonio Cuni avatar Antonio Cuni committed 18e1209

make sure that the server is always stopped

Comments (0)

Files changed (1)

         run_server_and_browser(app, run, url, filename)
 
 def run_server_and_browser(app, run, url, filename):
-    # start the HTTP server in another thread
-    th = threading.Thread(target=run)
-    th.start()
-    #
-    # start the webkit browser in the main thread (actually, it's a subprocess, but still)
-    time.sleep(0.5) # give the server some time to start
-    ret = start_browser(url, filename)
-    #
-    # shutdown the HTPP server and wait until it completes
-    app.servers[0].shutdown()
-    th.join()
+    try:
+        # start the HTTP server in another thread
+        th = threading.Thread(target=run)
+        th.start()
+        #
+        # start the webkit browser in the main thread (actually, it's a subprocess)
+        time.sleep(0.5) # give the server some time to start
+        ret = start_browser(url, filename)
+    finally:
+        # shutdown the HTPP server and wait until it completes
+        app.servers[0].shutdown()
+        th.join()
 
 def start_browser(url, filename):
     import subprocess
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.