Skip to content

Commit c5e49b8

Browse files
committed
Better handling of exceptions and messages in server start/stop activities
1 parent c9f2942 commit c5e49b8

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

egdsimulator_http.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,28 @@ def boot(argv):
274274
httpd.allow_reuse_address = True
275275
httpd.daemon_threads = True
276276
try:
277+
print("\nCreating HTTP server...")
277278
httpd.server_bind()
278279
httpd.server_activate()
279-
print("\n " + sys.argv[0] + " HTTP server is listening on port " + str(HTTP_PORT) + "...")
280+
print(sys.argv[0] + " HTTP server is listening on port " + str(HTTP_PORT) + "...")
280281
httpd.serve_forever()
281-
except:
282-
pass
282+
except KeyboardInterrupt as e:
283+
print("Interrupted by user...")
284+
except Exception as e:
285+
print(e)
286+
print(traceback.format_exc())
283287

284-
simulator.stop()
285-
httpd.shutdown()
286-
httpd.server_close()
288+
try:
289+
print("Stopping simulator...")
290+
simulator.stop()
291+
print("Stopping HTTP server...")
292+
httpd.shutdown()
293+
httpd.server_close()
294+
except Exception as e:
295+
print(e)
296+
print(traceback.format_exc())
297+
298+
sys.exit(1)
287299

288300
if __name__ == "__main__":
289301
boot(sys.argv)

0 commit comments

Comments
 (0)