Skip to content

Commit

Permalink
fix only terminate ffmpeg if instance exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Bleuzen committed May 14, 2018
1 parent 9a5557c commit 81b5643
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions spotifyrecorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,24 @@ def record(self, filename):

# The blocking version of this method waits until the process is dead
def stopBlocking(self):
# Remove from instances list
# Remove from instances list (and terminate)
if self in self.instances:
self.instances.remove(self)

# Send CTRL_C
self.process.terminate()
# Send CTRL_C
self.process.terminate()

print("[FFmpeg] [" + self.pid + "] terminated")
print("[FFmpeg] [" + self.pid + "] terminated")

# Sometimes this is not enough and ffmpeg survives, so we have to kill it after some time
time.sleep(1)
# Sometimes this is not enough and ffmpeg survives, so we have to kill it after some time
time.sleep(1)

if self.process.poll() == None:
# None means it has no return code (yet), with other words: it is still running
if self.process.poll() == None:
# None means it has no return code (yet), with other words: it is still running

self.process.kill()
self.process.kill()

print("[FFmpeg] [" + self.pid + "] killed")
print("[FFmpeg] [" + self.pid + "] killed")

# Remove process from memory (and don't left a ffmpeg 'zombie' process)
self.process = None
Expand Down

0 comments on commit 81b5643

Please sign in to comment.