2

I'm trying to end a subprocess that I've opened in a new window with:

alarm = subprocess.Popen(['lxterminal', '-e', 'python alarm.py'])

I'm trying to get it so that when a certain command is received. It ends execution of the script by closing the window.

I've tried the .kill command as well as many others, but nothing seems to work.

Edit: Additional code:

if (push.body == 'Alarm Test'):
    alarm = subprocess.Popen(['python', 'alarm.py'])
if (push.body == 'Alarm End'):
    alarm.kill()
Keva161
  • 2,623
  • 9
  • 44
  • 68
  • to clarify a little bit: you have a process `lxterminal` and you want that your main processes (that have started `lxterminal`) tells `lxterminal` to stop? Also, is there any reason, why you dont use threads? – DiKorsch Jan 08 '17 at 16:07
  • nothing seems to work? what happens? does the program ends without closing the window? – Jean-François Fabre Jan 08 '17 at 16:09
  • Ah I forgot about threads... this is my first time coding in a while :) – Keva161 Jan 08 '17 at 16:12
  • And to clarify.. nothing works as in nothing does the trick.. the process doesn't end even though I can debug the application to see that the command has been received. – Keva161 Jan 08 '17 at 16:13
  • can you post a little more of you code? – Jean-François Fabre Jan 08 '17 at 16:20
  • you could either use stdin and stdout as shown here: http://stackoverflow.com/a/16769956/1360842 or use shared memory to store a condition variable, which can be written by the main thread and read by the second one OR use threads, as all of your created threads automatically share the memory, you can easily set a variable from your main thread and read this variable from the created thread. Because your 2nd only reads the variable no synchronization should be needed – DiKorsch Jan 08 '17 at 16:21
  • First post update with additional code – Keva161 Jan 08 '17 at 16:30

0 Answers0