简体   繁体   English

Python:运行变成后台进程的脚本立即死亡

[英]Python: running a script that turns into a background process dies immediatly

I'm working on a piece of code in python where I'm using parallel-ssh to run a script on a Raspberry Pi. 我正在使用python中的一段代码在其中使用parallel-ssh在Raspberry Pi上运行脚本。 The script runs for about a 1 and then disappears even though there is nohup in the script. 该脚本运行约1,然后消失,即使脚本中没有nohup

Code to run the script from server: 从服务器运行脚本的代码:

return subprocess.call(["parallel-ssh", "-h", hosts_path, "-o", "pssh-out", "-e", "pssh-err", "-i" if inline else "", cmd])

and on the Raspberry Pi the script looks like this: 在Raspberry Pi上,脚本如下所示:

log_path=$1

tty_path=`ls /dev/serial/by-id/usb-MBED_MBED_CMSIS-DAP_*`
nohup /home/pi/scripts/ble/contiki-serialdump -b9600 $tty_path | /home/pi/scrip$


sleep 1
ps | grep "$! "

#exit $?

Any ideas why it doesn't keep running in the background? 有什么想法为什么它不能一直在后台运行吗?

Your script isn't waiting before it exits. 您的脚本在退出之前没有等待。 You'll need a shell with job control (such as Bash), and use the wait builtin command. 您将需要一个具有作业控制功能的shell(例如Bash),并使用wait内建命令。 Read the bash man page to understand wait . 阅读bash手册页以了解wait

问题显然是必须关闭然后打开USB集线器才能正确启动串行转储

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM