【发布时间】:2021-12-21 16:32:42
【问题描述】:
我想要做的是同时运行两个 python 脚本,然后在命令中将它们都杀死。我不太精通 bash 脚本,但这是我目前在 bash 脚本中的内容:
python3 appcode.py &
python3 igc.py &
但是,当我运行它时,当我用它的 PID 终止进程时,bash 脚本会不断重新启动。然后我将其重写为在运行这些脚本后有一个退出命令,这会停止 bash,但脚本会继续在后台运行。
我将如何编写它,以便当我在启动它的终端中输入 ctrl-c 或其他键输入时,python 脚本和 bash 脚本都将同时结束?谢谢!
编辑:
我将一个导入另一个并以这种方式运行它,但是我使用的是 Pyautogui 和 PyQt5,当我将 pyautogui 脚本导入到具有 PyQt5 的脚本中时,我遇到了这个错误:
QObject::moveToThread: Current thread (0x1894380) is not the object's thread (0x2042850).
Cannot move to target thread (0x1894380)
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/connor/.local/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.
Aborted (core dumped)
【问题讨论】:
-
拥有一个 python 脚本来导入这两个文件并使用多处理或类似机制启动功能不是更有意义吗? “杀戮”其实只是万不得已的手段。
-
欢迎来到 Stack Overflow (SO)。 SO is a question and answer page for professional and enthusiast programmers。请在您的问题中添加您自己的代码。您应该至少展示自己为解决这个问题所做的研究。
标签: python python-3.x bash