Skip to content

Problems & Solutions

Logan Crandall edited this page Mar 19, 2021 · 1 revision

Problems & Solutions

For when we are asked "what are the technical challenges" or when we write a report / presentation.

Taking too long to convert video stream frames to camera input frames

Camera and webserver ran on a worker thread separate from the main thread initially. The assumption was that because it was on the worker thread, it could run in parallel with the main thread and we would gain performance due to task division. With Python this wasn't the case due to the Global Interpret Lock (GIL). The GIL is a global mutex that Python uses that prevents two threads from actually executing simultaneously even though they may be on different CPU cores. This means that video decoding is happening for a period of time, then the main thread is executing, then the video decoding - not ideal and leads to extreme slowdowns.

Solution

Python provides a module called multiprocessing that allows spawning of child processes. So instead of Python handling multithreading, the operating systems scheduler is used to truly parallelize the application, allowing for faster video decoding since we are not waiting on the main process anymore.