繁体   English   中英

为什么在我终止程序后我的 linux 上的 python 程序没有执行?

[英]Why is my python program on linux not executing after i terminate the program?

运行程序时的终端结果 我在 linux 中运行 python 脚本,我在多次运行程序时遇到问题。 当我执行程序时,程序运行正常,我给它一个 SIGTSTP 信号 ctrl+z 来终止程序。 但是,当我再次运行该程序时,该程序不会执行并且 linux 提示我输入一个新命令。 我尝试杀死 pids 和终止进程,但它没有解决问题。 我必须重新启动系统才能使程序再次运行。 请提供解决方案的建议,以便我可以终止程序并再次运行它而无需重新启动我的系统。

SIGSTOP不会终止程序,它会暂停它,因此它不会被杀死。 您应该向程序发送SIGCONT或键入fg以继续它。

SIGTSTP 或 SIGSTOP 信号被挂起,不能杀死这个程序,使用 SIGCONT 信号你可以唤醒并继续它

Signal  Description Signal number on Linux x86[1]
SIGABRT Process aborted 6
SIGALRM Signal raised by alarm  14
SIGBUS  Bus error: "access to undefined portion of memory object"   7
SIGCHLD Child process terminated, stopped (or continued*)   17
SIGCONT Continue if stopped 18
SIGFPE  Floating point exception: "erroneous arithmetic operation"  8
SIGHUP  Hangup  1
SIGILL  Illegal instruction 4
SIGINT  Interrupt   2
SIGKILL Kill (terminate immediately)    9
SIGPIPE Write to pipe with no one reading   13
SIGQUIT Quit and dump core  3
SIGSEGV Segmentation violation  11
SIGSTOP Stop executing temporarily  19
SIGTERM Termination (request to terminate)  15
SIGTSTP Terminal stop signal    20
SIGTTIN Background process attempting to read from tty ("in")   21
SIGTTOU Background process attempting to write to tty ("out")   22
SIGUSR1 User-defined 1  10
SIGUSR2 User-defined 2  12
SIGPOLL Pollable event  29
SIGPROF Profiling timer expired 27
SIGSYS  Bad syscall 31
SIGTRAP Trace/breakpoint trap   5
SIGURG  Urgent data available on socket 23
SIGVTALRM   Signal raised by timer counting virtual time: "virtual timer expired"   26
SIGXCPU CPU time limit exceeded 24
SIGXFSZ File size limit exceeded    25

您应该确保您的线程在守护进程模式下运行。 当您点击ctrl-c时,这可能是阻止它们干净退出的原因。 像这样设置它们:

t = threading.Thread()
t.daemon = True  // <- this is the important bit...
t.start()

好的,我找到了解决方案。

在你的 linux 终端上输入以下命令:

ps -ef |grep yourfile.py

您将看到许多仍在后台运行的进程。 要杀死它们,请输入以下命令:

kill -9 pid

不要输入pid。 键入标识进程的数字,如终端显示中所示

杀死不允许您执行程序的后台进程

使用以下命令杀死所有进程并确保没有后台进程在运行。

Ctrl+\\

暂无
暂无

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

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