Skip to content

Commit

Permalink
Use 'proc.poll()' to make sure that processes should be terminated (#…
Browse files Browse the repository at this point in the history
…1296)

* fix to terminate the process that has ended

check if the process exists before using teminate() to stop the process.

* Update readers.py

* fix to terminate the process which has been killed

* Use proc.poll() is video reader 'close()'
  • Loading branch information
luyanger1799 authored Jan 13, 2021
1 parent 023c8b3 commit aa861a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions moviepy/audio/io/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,11 @@ def buffer_around(self, frame_number):

def close(self):
if self.proc:
self.proc.terminate()
self.proc.stdout.close()
self.proc.stderr.close()
self.proc.wait()
if self.proc.poll() is None:
self.proc.terminate()
self.proc.stdout.close()
self.proc.stderr.close()
self.proc.wait()
self.proc = None

def __del__(self):
Expand Down
9 changes: 5 additions & 4 deletions moviepy/video/io/ffmpeg_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,11 @@ def get_frame_number(self, t):

def close(self, delete_lastread=True):
if self.proc:
self.proc.terminate()
self.proc.stdout.close()
self.proc.stderr.close()
self.proc.wait()
if self.proc.poll() is None:
self.proc.terminate()
self.proc.stdout.close()
self.proc.stderr.close()
self.proc.wait()
self.proc = None
if delete_lastread and hasattr(self, "last_read"):
del self.last_read
Expand Down

0 comments on commit aa861a6

Please sign in to comment.