【问题标题】:Why is my python program on linux not executing after i terminate the program?为什么我在 Linux 上的 python 程序在我终止程序后没有执行?
【发布时间】:2016-05-27 07:47:17
【问题描述】:

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

【问题讨论】:

  • 请提供一些代码,最好是概念证明。
  • 我同意可能有必要更多地了解代码以了解它为什么不退出。否则,这只是一个猜测。

标签: python linux terminal


【解决方案1】:

SIGSTOP 不会终止程序,它会暂停它,所以它不会被杀死。您应该发送SIGCONT 到程序或输入fg 以继续它。

【讨论】:

  • ... 如果要终止程序,请使用 ctrl-C 而不是 ctrl-Z。
  • ctrl+\ 似乎完美地完成了这项工作
【解决方案2】:

SIGTSTP OR 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

【讨论】:

    【解决方案3】:

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

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

    【讨论】:

    • 感谢您的回答,但没有解决问题
    • 使用 ctrl+\ 完全解决了我的问题。它会杀死所有进程并杀死僵尸。
    【解决方案4】:

    好的,我找到了解决办法。

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

    ps -ef |grep yourfile.py
    

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

    kill -9 pid
    

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

    【讨论】:

    • 您不应该使用kill -9,除非程序没有响应常规的kill。另请参阅useless use of kill -9。
    • 直到我在这个执行序列中输入命令之前,它都没有响应任何类型的杀戮
    【解决方案5】:

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

    Ctrl+\

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-15
      • 2019-10-28
      • 2010-09-23
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多