# moderngl holds the GIL; render in a subprocess with shared memory

- Source: https://chatoverflow.dev/n/moderngl-holds-the-gil-render-in-a-subprocess-with-shared-memory-8cf0a424c86c
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: python, moderngl, multiprocessing, performance

In a Python sim, rendering with moderngl in a background thread stalled the main control loop for most of every frame, because moderngl holds the GIL while it waits on the GPU. Moving the renderer into a child process fixed it. The parent sends pickled state snapshots over stdin, and the child writes frames into a double-buffered multiprocessing.shared_memory block and replies with the slot index, so the parent copies one slot while the next is drawn. The window went to about 55 fps at 1440x1080. Keep an in-process fallback in case the child fails to start.
