mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Fix mpv being left around on abrupt termination (#4042)
Closes #4015
(cherry picked from commit f81a9bfdfb
)
This commit is contained in:
parent
f3acf5fe59
commit
711db1ee0c
1 changed files with 17 additions and 0 deletions
|
@ -68,6 +68,7 @@ if is_win:
|
||||||
# pylint: disable=import-error
|
# pylint: disable=import-error
|
||||||
import pywintypes
|
import pywintypes
|
||||||
import win32file # pytype: disable=import-error
|
import win32file # pytype: disable=import-error
|
||||||
|
import win32job
|
||||||
import win32pipe
|
import win32pipe
|
||||||
import winerror
|
import winerror
|
||||||
|
|
||||||
|
@ -130,6 +131,22 @@ class MPVBase:
|
||||||
def _start_process(self):
|
def _start_process(self):
|
||||||
"""Start the mpv process."""
|
"""Start the mpv process."""
|
||||||
self._proc = subprocess.Popen(self.argv, env=self.popenEnv)
|
self._proc = subprocess.Popen(self.argv, env=self.popenEnv)
|
||||||
|
if is_win:
|
||||||
|
# Ensure mpv gets terminated if Anki closes abruptly.
|
||||||
|
self._job = win32job.CreateJobObject(None, "")
|
||||||
|
extended_info = win32job.QueryInformationJobObject(
|
||||||
|
self._job, win32job.JobObjectExtendedLimitInformation
|
||||||
|
)
|
||||||
|
extended_info["BasicLimitInformation"][
|
||||||
|
"LimitFlags"
|
||||||
|
] = win32job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
|
||||||
|
win32job.SetInformationJobObject(
|
||||||
|
self._job,
|
||||||
|
win32job.JobObjectExtendedLimitInformation,
|
||||||
|
extended_info,
|
||||||
|
)
|
||||||
|
handle = self._proc._handle # pylint: disable=no-member
|
||||||
|
win32job.AssignProcessToJobObject(self._job, handle)
|
||||||
|
|
||||||
def _stop_process(self):
|
def _stop_process(self):
|
||||||
"""Stop the mpv process."""
|
"""Stop the mpv process."""
|
||||||
|
|
Loading…
Reference in a new issue