Skip to content

Crash during long running proccess in asyncio.create_subprocess_shell on Windows #62

@esmorun

Description

@esmorun

Hi, I'm executing ffmpeg in an asyncio subprocess to convert a video. Example:

command = "ffmpeg  -i \"video.mp4\" -c:v hevc_nvenc -rc constqp -qp 27 -c:a libopus -b:a 96k \"video.mkv\""
proc = await asyncio.create_subprocess_shell(command, stdin=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)

Long running processes will eventually crash the entire PyQt GUI. Sometimes it just crashes to desktop without any output in the Python shell, and sometimes this error message appears:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\qasync\_windows.py", line 163, in run
    events = self.__proactor.select(0.01)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\qasync\_windows.py", line 69, in select
    self._poll(timeout)
  File "C:\Users\User\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\qasync\_windows.py", line 99, in _poll
    with QtCore.QMutexLocker(self._lock):
RuntimeError: wrapped C/C++ object of type QMutex has been delet

The ffmpeg process continues as an orphaned process and finishes the job. Can anybody shed some light on what might be happening? I have tested the same code on Ubuntu and MacOS and have not encountered any issues.

I'm on PyQt 6.2.2 and Python 3.9.9.

Edit: I now understand that the error is happening because the QMutex object that is created on line 64 in windows.py is deleted before the loop at line 100 in the _poll function finishes. Just for fun I tried to remove the QMutexLocker by removing line 99:
with QtCore.QMutexLocker(self._lock):

...and this actually prevents my app from crashing, but I assume this is not a solution and the lock was there for a reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneed reproNeeds minimal, reproducible example

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions