Skip to content

Commit 3170413

Browse files
Merge pull request #189 from runpod/fix-stdout-srderr
Fix stdout srderr
2 parents 8162556 + dc7a09c commit 3170413

File tree

6 files changed

+22
-7
lines changed

6 files changed

+22
-7
lines changed

docs/cli/demos/config.gif

-274 Bytes
Loading

docs/cli/demos/help.gif

113 Bytes
Loading

docs/cli/demos/ssh.gif

352 Bytes
Loading

runpod/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@
3737
# --------------------------- Force Logging Levels --------------------------- #
3838
logging.getLogger("urllib3").setLevel(logging.WARNING)
3939
logging.getLogger("paramiko").setLevel(logging.WARNING)
40+
logging.getLogger("uvicorn").setLevel(logging.WARNING)

runpod/cli/groups/project/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,13 @@ def start_project_api():
250250
# Start the API server in the background, and save the PID
251251
python {handler_path} --rp_serve_api --rp_api_host="0.0.0.0" --rp_api_port=8080 --rp_api_concurrency=1 &
252252
last_pid=$!
253+
253254
echo -e "- Started API server with PID: $last_pid" && echo ""
254255
echo "> Connect to the API server at:"
255256
echo "https://$RUNPOD_POD_ID-8080.proxy.runpod.net/docs" && echo ""
256257
257258
while true; do
258-
if changed_file=$(inotifywait -r -e modify,create,delete --exclude "$exclude_pattern" {remote_project_path} --format '%w%f'); then
259+
if changed_file=$(inotifywait -q -r -e modify,create,delete --exclude "$exclude_pattern" {remote_project_path} --format '%w%f'); then
259260
echo "Detected changes in: $changed_file"
260261
else
261262
echo "Failed to detect changes."
@@ -269,10 +270,9 @@ def start_project_api():
269270
python -m pip install --upgrade pip && python -m pip install -r {requirements_path}
270271
fi
271272
272-
sleep 1 #Debounce
273-
274273
python {handler_path} --rp_serve_api --rp_api_host="0.0.0.0" --rp_api_port=8080 --rp_api_concurrency=1 &
275274
last_pid=$!
275+
276276
echo "Restarted API server with PID: $last_pid"
277277
done
278278
''']

runpod/cli/utils/ssh_cmd.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
Connect and run commands over SSH.
55
'''
6+
import threading
67
import subprocess
78
import colorama
89
import paramiko
@@ -47,14 +48,27 @@ def _get_ssh_options(self):
4748

4849
def run_commands(self, commands):
4950
''' Runs a list of bash commands over SSH. '''
51+
def handle_stream(stream, color, prefix):
52+
for line in stream:
53+
if line:
54+
print(color + f"[{prefix}]", line.strip())
55+
5056
for command in commands:
5157
command = f'source /root/.bashrc && {command}'
5258
command = f'source /etc/rp_environment && {command}'
59+
command = f'while IFS= read -r -d \'\' line; do export "$line"; done < /proc/1/environ && {command}' # pylint: disable=line-too-long
5360
_, stdout, stderr = self.ssh.exec_command(command)
54-
for line in stdout:
55-
print(colorama.Fore.GREEN + f"[{self.pod_id}]", line.strip())
56-
for line in stderr:
57-
print(colorama.Fore.RED + f"[{self.pod_id} ERROR]", line.strip())
61+
62+
stdout_thread = threading.Thread(
63+
target=handle_stream, args=(stdout, colorama.Fore.GREEN, self.pod_id))
64+
stderr_thread = threading.Thread(
65+
target=handle_stream, args=(stderr, colorama.Fore.RED, self.pod_id))
66+
67+
stdout_thread.start()
68+
stderr_thread.start()
69+
70+
stdout_thread.join()
71+
stderr_thread.join()
5872

5973
def put_file(self, local_path, remote_path):
6074
''' Copy local file to remote machine over SSH. '''

0 commit comments

Comments
 (0)