I have asked a question how to run a clipboard clearing command from python, and I got a good answer for that:

我问了一个如何从python运行剪贴板清除命令的问题,我得到了一个很好的答案:

subprocess.run("xclip",stdin=subprocess.DEVNULL)
subprocess.run(["xclip","-selection","clipboard"],input="")

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.

这似乎在python中工作,但是有一个问题,它使进程保持打开状态。实际上它打开了2个进程,一个是xclip,另一个是xclip -selection剪贴板参数。

And it seems like they are zombie processes, they remain there indefinitely, until you copy-paste something again. After that both of them dissapear.

它们似乎是僵尸进程,它们会无限期地保留在那里,直到你再次复制粘贴。之后他们两个都消失了。

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.

所以我从USB驱动器的目录运行脚本,并且它不允许你移除USB驱动器,它说“USB驱动器忙”,直到进程没有关闭。

So either I copy something new into the clipboard, otherwise the process remains there indefinitely, like a zombie.

所以要么我将一些新东西复制到剪贴板中,否则进程会无限期地保留在那里,就像一个僵尸。

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.

是否可以在python脚本结束后关闭进程?由于没有理由在python脚本运行后该进程保持打开状态。

1 个解决方案

#1


0

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:

我必须阅读xclip的源代码,看看父母(你的直接孩子)是否等到所谓的选择被退出。如果没有,如果你杀了任何东西,你会与实际工作竞争。您可以使用xsel -c(如其他问题中所建议的那样);要解决卸载问题,您只需更改子项的当前目录:

subprocess.run("xclip",stdin=subprocess.DEVNULL,cwd="/")

更多相关文章

  1. 使用nagios+python监控nginx进程数
  2. python subprocess模块 监控子进程的2种方式 忙等待和立即返回同
  3. 初探Linux kernel之进程相关二
  4. 检查进程是否仍在运行
  5. 解决僵尸进程
  6. Linux网络和进程管理命令
  7. Linux 下nice 函数用法提高一个进程的友善值
  8. linux系统编程之进程(八):守护进程详解及创建,daemon()使用
  9. Linux进程通信之匿名管道

随机推荐

  1. android实现定时拍照并发送微博功能
  2. Android: 更改语言时Launcher2更新apps
  3. Android Studio出错异常汇总
  4. Android Wear Preview- 为通知添加多个页
  5. 检查internet连接
  6. Android 控件的显示隐藏上下左右移动动画
  7. Android复制粘贴到剪贴板
  8. Android(安卓)API 28 使用 android-async
  9. Android Wear Preview- 从通知上接收语音
  10. Android 开源框架的收集