[Bug] PyInstaller threading/GIL issue

Summary

I’m having a similar issue to an already existing post which never got a solution so I’m opening another topic here.

I’m having a runtime issue running a PyInstaller executable of a hailo AI application, which is producing this as the main error message..

Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)

System

  • Hardware: Raspberry Pi 5
  • OS: Debian GNU/Linux 12 (bookworm)
  • Acceleration: Both Hailo8 and Hailo8L tested
  • Model: yolov8s.hef and yolov8n.hef tested
  • Packaging Tool: PyInstaller

What Works

Running the application via the Python interpreter

python main.py

All functionality I expect from my application works, including sending serial packets to an Arduino board, requesting images from a camera and putting them into a hailo detection pipeline.

What Fails

After packaging the application with pyinstaller, running the executable no longer provides the expected functionality and outputs this error.

./dist/main/main

*other startup log messages*
Starting GStreamer pipeline...
Auto-detected Hailo architecture: hailo8
Fatal Python error: PyThreadState_Get: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized

The culprit is in a derived class of the GStreamerApp. Here is a sample of the code to demonstrate..

class GStreamerDetectionApp(GStreamerApp):
  def __init__(self):
    # Gathers some information and sets some variables
    print("this message shows in the output")
    self.create_pipeline() # Error occurs here
    print("this message does not show in the output")

Although I know where the code breaks, I have no idea why.

What I’ve tried

  • Checked for the hailo library in the dist folder. hailo.cython… is present
  • Built with two different accelerators and on different machines
  • Built different versions of my software, all come back with the same error regarding GIL

Any help I can get with this would be much appreciated, thank you!

Did you try ChatGPT? It gave me a comprehensive analysis.

Yes I did. The information and guidance I got from it wasn’t very helpful and got me no closer to solving the issue