From 929ebdb7589bf94d6bd758af3b8488648ecf95da Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 21 Mar 2025 13:50:35 +0000 Subject: [PATCH] Flush output in Python before running execvp (#2258) --- images/base-notebook/start-notebook.py | 5 +++-- images/base-notebook/start-singleuser.py | 2 +- tests/by_image/base-notebook/test_start_container.py | 6 +----- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/images/base-notebook/start-notebook.py b/images/base-notebook/start-notebook.py index 973da5aa..0619aa28 100755 --- a/images/base-notebook/start-notebook.py +++ b/images/base-notebook/start-notebook.py @@ -8,7 +8,8 @@ import sys # If we are in a JupyterHub, we pass on to `start-singleuser.py` instead so it does the right thing if "JUPYTERHUB_API_TOKEN" in os.environ: print( - "WARNING: using start-singleuser.py instead of start-notebook.py to start a server associated with JupyterHub." + "WARNING: using start-singleuser.py instead of start-notebook.py to start a server associated with JupyterHub.", + flush=True, ) command = ["/usr/local/bin/start-singleuser.py"] + sys.argv[1:] os.execvp(command[0], command) @@ -40,5 +41,5 @@ if "NOTEBOOK_ARGS" in os.environ: command += sys.argv[1:] # Execute the command! -print("Executing: " + " ".join(command)) +print("Executing: " + " ".join(command), flush=True) os.execvp(command[0], command) diff --git a/images/base-notebook/start-singleuser.py b/images/base-notebook/start-singleuser.py index 8fe0e9ef..01553264 100755 --- a/images/base-notebook/start-singleuser.py +++ b/images/base-notebook/start-singleuser.py @@ -20,5 +20,5 @@ if "NOTEBOOK_ARGS" in os.environ: command += sys.argv[1:] # Execute the command! -print("Executing: " + " ".join(command)) +print("Executing: " + " ".join(command), flush=True) os.execvp(command[0], command) diff --git a/tests/by_image/base-notebook/test_start_container.py b/tests/by_image/base-notebook/test_start_container.py index 7e7af043..e5958cb3 100644 --- a/tests/by_image/base-notebook/test_start_container.py +++ b/tests/by_image/base-notebook/test_start_container.py @@ -42,11 +42,7 @@ def test_start_notebook( f"Test that the start-notebook.py launches the {expected_command} server from the env {env} ..." ) host_port = find_free_port() - container.run_detached( - tty=True, - environment=env, - ports={"8888/tcp": host_port}, - ) + container.run_detached(environment=env, ports={"8888/tcp": host_port}) # sleeping some time to let the server start time.sleep(2) logs = container.get_logs()