Cannot find pid of daemonized python thread using ps aux

问题描述 投票:0回答:0

我在 rhel 7 机器上运行以下程序:

(python3.9)

import threading
import time

def countdown(count):
  print(f'Thread alive? {thread.is_alive()}')
  print("Counting down...")
  while count > 0:
    print(f'{count} left')
    count -= 1
    time.sleep(2)
  print("We made it!")

thread = threading.Thread(target=countdown, args=(500,))
thread.setDaemon(True)
thread.start()


while True:
  time.sleep(2)
  print(f'Thread still alive? {thread.is_alive()}')
  print(f'The trhead id: {thread.native_id}')
print("End of program.")

enter image description here

如下图,daemonized子线程的native thread id是28435,但是用ps aux查找这个线程时找不到,也不能只杀子线程不杀主线程(用杀死-9 28435) enter image description here

enter image description here

如果子线程正在运行,我在哪里可以看到使用 bash?我怎样才能在不杀死主线程的情况下只从命令行杀死子进程?

我尝试了不同的终止级别,但似乎都停止了主线程,而且我无法使用 top 命令找到 pid。

python linux bash python-multithreading
© www.soinside.com 2019 - 2024. All rights reserved.