How to start the process and exit after the script finishes?

I asked the question how to run the clipboard cleanup command from python , and I got a good answer for this :

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

This seems to work in python, but there is a problem and the process remains open. In fact, it opens 2 processes, one xclipand one with parameters xclip -selection clipboard.

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

So, I ran the script from the directory of the USB drive, and it does not allow you to remove the USB drive, it says "USB drive busy" until the processes are closed.

So either I copy something new to the clipboard, otherwise the process remains there indefinitely, like zombies.

Is it possible to just close the process after the python script has finished ? Since there is no reason for this process to remain open after running the python script.

+1
source share
1 answer

I would need to read the xclipsource to find out if the parent (your direct child) is waiting until the choice is announced. If not, you will participate in real work if you killed something. You can use xsel -c(as suggested in another question); to solve only the unmount problem, you can simply change the current directory of the child:

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

Source: https://habr.com/ru/post/1692848/