我问了一个问题如何运行来自 python 的剪贴板清除命令和我得到了一个很好的答案:
subprocess.run("xclip",stdin=subprocess.DEVNULL) subprocess.run(["xclip","-selection","clipboard"],input="")这似乎在 python 中工作,但有一个问题,它使进程处于打开状态.实际上它打开了 2 个进程,一个 xclip 和一个带有 xclip -selection clipboard 参数.
This seem to work in python, but there is a problem, it leaves the process open. Actually it opens 2 processes, one xclip and one with xclip -selection clipboard parameters.
而且它们似乎是僵尸进程,它们无限期地保留在那里,直到您再次复制粘贴某些内容.之后两人都消失了.
And it seems like they are zombie processes, they remain there indefinitely, until you copy-paste something again. After that both of them dissapear.
所以我从 USB 驱动器的目录运行脚本,它不允许您移除 USB 驱动器,它会显示USB 驱动器忙",直到进程没有关闭.
So I have run the script from an USB drive's directory, and it doesn't let you remove the USB drive, it says "USB drive busy", until the processes don't close.
所以要么我把新的东西复制到剪贴板,否则这个过程会无限期地留在那里,就像一个僵尸.
So either I copy something new into the clipboard, otherwise the process remains there indefinitely, like a zombie.
是否可以在 python 脚本结束后关闭进程?因为在 python 脚本运行后,该进程没有理由保持打开状态.
Is it possible to just close the process after the python script ends? Since there is no reason for that process to remain open after the python script has ran.
推荐答案我必须阅读 xclip 的源代码以查看父级(您的直接子级)是否等待选择完成声称退出.如果没有,如果你杀了任何东西,你就会与实际工作竞争.您可以使用 xsel -c (正如在另一个问题中所建议的那样);解决只是卸载问题,你可以简单地改变孩子的当前目录:
I'd have to read xclip's source to see if the parent (your direct child) waits until the selection has been claimed to exit. If not, you would race with the actual work if you killed anything. You can use xsel -c (as was suggested in the other question); to solve just the unmounting problem, you can simply change the current directory of the child:
subprocess.run("xclip",stdin=subprocess.DEVNULL,cwd="/")更多推荐
脚本结束后如何运行进程并退出?
发布评论