3

I am trying to use python to close VLC while it is recording audio. Currently I am using:

os.kill(pid,pid)

This works but is closing VLC abruptly and not allowing the recording file to close properly, thus corrupting it. If I manually close the VLC GUI instance than the recording file will not be corrupted.

So basically I am looking for a python command to close an application that emulates the 'Close' button on the application's GUI.

Or, perhaps there is another way. Such as closing the .wav file where the recording is being written, before killing the VLC process? I also put some work into this, but didn't get any results.

Thanks for the help!

4
  • 1
    which OS does this have to work on? Commented Aug 5, 2013 at 12:42
  • 2
    What signal are you sending? (The signature is os.kill(pid, sig)) Commented Aug 5, 2013 at 12:46
  • Sorry, I am running on Windows 7, and the pid I am sending in is the actual PID of VLC. Commented Aug 5, 2013 at 13:00
  • You should send a WM_CLOSE message to the VLC process via a win32api.SendMessage() call. Commented Jul 10, 2022 at 15:04

2 Answers 2

7

You're using the function wrong, you'll likely want something like this:

from signal import SIGTERM
os.kill(pid,SIGTERM)

The second parameter specifies the interrupt. Also often used is SIGKILL which is a hard kill, likely same as you had before. You can find more about the linux signals here. In windows your options are more limited, see the python docs for available signals.

By providing pid also for the second parameter you probably set a quite heavy kill signal, that terminated the application immediately, without closing files.

Sign up to request clarification or add additional context in comments.

3 Comments

Are you sure SIGQUIT is the appropriate signal (it instructs the process to perform a core dump). Reading libc termination signals it seems to me SIGTERM or SIGINT would be more appropriate. Other than that, +1 :)
@LukasGraf: Changed it back to SIGTERM, the info I found on SIGQUIT was a bit confusing, thanks.
So I am still running into the same problem. But I will play around with a few other parts of my program and see if I can get this working. I'll post back after that with my results. Thanks!
0

I think I got it working. Instead of using os.kill() I am using

os.system("taskkill /pid " +str(pid)+ " /t")

This closes the recording without corrupting the file. Also if anyone else has this problem and is recording with VLC command line, this does not seem to work if the dummy interface is used.

1 Comment

subprocess.call(['taskkill', '/pid', str(pid), '/t']) is cleaner than using the deprecated os.system().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.