Reputation: 759
I am trying to execute a Python script on a remote server via SSH. The script is supposed to run a certain function every few seconds. A minimal working snippet is as follows:
# test.py (this is on the remote server in $HOME)
import sys
import time
def test(num_samples):
# First start with a monitoring period of 50 seconds.
monitoring_period = 5
a = 0
while a < num_samples:
print(a, num_samples)
time.sleep(monitoring_period)
a += 1000
if __name__ == "__main__":
print("Start")
test(int(sys.argv[1]))
When I run the above script directly on the remote server, it executes successfully:
node0:~$ python test.py 500
Start
0 500
However, when I try to run the same script via SSH - it just stalls (and note that even the first print statement "Start" is also not executed:
❯ ssh -o StrictHostKeyChecking=no <user>@<remote-server> "pushd \$HOME; python test.py 500"
~ ~
// It stalls here
More interestingly, if I remove the time.sleep(.)
statement from the above script, it executes just fine:
❯ ssh -o StrictHostKeyChecking=no <user>@<remote-server> "pushd \$HOME; python test.py 500"
~ ~
Start
0 500
sleep(.)
statement cause this issue?print("Start")
statement)?Upvotes: 0
Views: 22