Skip to content

Commit

Permalink
#3483 OpenGL may import numpy via its array modules
Browse files Browse the repository at this point in the history
we don't want to fail to enable OpenGL acceleration just because the codec initialization thread is also initializing numpy, so wait for it to complete
  • Loading branch information
totaam committed Jan 16, 2024
1 parent 946a039 commit 7acbcaf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions xpra/platform/posix/gl_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
from typing import Any
from contextlib import AbstractContextManager
from ctypes import c_int, c_void_p, byref, cast, POINTER
from OpenGL import GLX
from OpenGL.GL import GL_VENDOR, GL_RENDERER, glGetString
from OpenGL.raw.GLX._types import struct__XDisplay, struct___GLXcontextRec

from xpra.os_util import gi_import
from xpra.util.env import envbool, envfloat
from xpra.util.env import envbool, envfloat, NumpyImportContext
from xpra.client.gl.check import check_PyOpenGL_support
from xpra.x11.bindings.display_source import get_display_ptr
from xpra.gtk.error import xsync
from xpra.gtk.window import set_visual
from xpra.log import Logger

with NumpyImportContext(True):
from OpenGL import GLX
from OpenGL.GL import GL_VENDOR, GL_RENDERER, glGetString
from OpenGL.raw.GLX._types import struct__XDisplay, struct___GLXcontextRec

log = Logger("opengl")


Expand Down
7 changes: 5 additions & 2 deletions xpra/util/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ def ignorewarnings(fn, *args) -> Any:

class NumpyImportContext(AbstractContextManager):

def __init__(self, blocking=False):
self.blocking = blocking

def __enter__(self):
if not numpy_import_lock.acquire(blocking=False):
if not numpy_import_lock.acquire(blocking=self.blocking):
raise RuntimeError("the numpy import lock is already held!")
os.environ["XPRA_NUMPY_IMPORT"] = "1"

Expand All @@ -187,7 +190,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
numpy_import_lock.release()

def __repr__(self):
return "numpy_import_context"
return f"numpy_import_context({self.blocking=})"


_saved_env = os.environ.copy()
Expand Down

0 comments on commit 7acbcaf

Please sign in to comment.