(self, timeout=0.5)
| 511 | return |
| 512 | |
| 513 | def serve_forever(self, timeout=0.5): |
| 514 | global page_exit_code, emrun_not_enabled_nag_printed |
| 515 | self.is_running = True |
| 516 | self.timeout = timeout |
| 517 | logi('Now listening at http://%s/' % ':'.join(map(str, self.socket.getsockname()))) |
| 518 | logv("Entering web server loop.") |
| 519 | while self.is_running: |
| 520 | now = tick() |
| 521 | # Did user close browser? |
| 522 | if emrun_options.run_browser and not is_browser_process_alive(): |
| 523 | logv("Shutting down because browser is no longer alive") |
| 524 | delete_emrun_safe_firefox_profile() |
| 525 | if not emrun_options.serve_after_close: |
| 526 | logv("Browser process has shut down, quitting web server.") |
| 527 | self.is_running = False |
| 528 | |
| 529 | # Serve HTTP |
| 530 | self.handle_request() |
| 531 | # Process message log queue |
| 532 | self.print_timed_out_messages() |
| 533 | |
| 534 | # If web page was silent for too long without printing anything, kill process. |
| 535 | time_since_message = now - last_message_time |
| 536 | if emrun_options.silence_timeout != 0 and time_since_message > emrun_options.silence_timeout: |
| 537 | self.shutdown() |
| 538 | logi(f'No activity in {emrun_options.silence_timeout} seconds. Quitting web server with return code {emrun_options.timeout_returncode}. (--silence-timeout option)') |
| 539 | page_exit_code = emrun_options.timeout_returncode |
| 540 | emrun_options.kill_exit = True |
| 541 | |
| 542 | # If the page has been running too long as a whole, kill process. |
| 543 | time_since_start = now - page_start_time |
| 544 | if emrun_options.timeout != 0 and time_since_start > emrun_options.timeout: |
| 545 | self.shutdown() |
| 546 | logi(f'Page has not finished in {emrun_options.timeout} seconds. Quitting web server with return code {emrun_options.timeout_returncode}. (--timeout option)') |
| 547 | emrun_options.kill_exit = True |
| 548 | page_exit_code = emrun_options.timeout_returncode |
| 549 | |
| 550 | # If we detect that the page is not running with emrun enabled, print a warning message. |
| 551 | if not emrun_not_enabled_nag_printed and page_last_served_time is not None: |
| 552 | time_since_page_serve = now - page_last_served_time |
| 553 | if not have_received_messages and time_since_page_serve > 10: |
| 554 | logv('The html page you are running is not emrun-capable. Stdout, stderr and exit(returncode) capture will not work. Recompile the application with the --emrun linker flag to enable this, or pass --no-emrun-detect to emrun to hide this check.') |
| 555 | emrun_not_enabled_nag_printed = True |
| 556 | |
| 557 | # Clean up at quit, print any leftover messages in queue. |
| 558 | self.print_all_messages() |
| 559 | logv("Web server loop done.") |
| 560 | |
| 561 | def handle_error(self, request, client_address): |
| 562 | err = sys.exc_info()[1].args[0] |
no test coverage detected