Skip to content

Commit

Permalink
#4457 block numpy import if not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Jan 6, 2025
1 parent 817d31d commit 76d46ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions xpra/scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,21 @@ def enforce_client_features() -> None:
"network_listener": "xpra.client.mixins.network_listener",
"encoding": "xpra.client.mixins.encodings",
})
may_block_numpy()


def may_block_numpy() -> None:
if envbool("XPRA_MAY_BLOCK_NUMPY", True) and "numpy" not in sys.modules:
reason = ""
try:
from xpra.codecs.nvidia.util import has_nvidia_hardware
if not has_nvidia_hardware():
reason = "no nvidia hardware"
except ImportError:
reason = "no nvidia codecs"
if reason:
get_logger().debug(f"{reason}, blocking `numpy` import")
sys.modules["numpy"] = None


def make_client(opts):
Expand Down
2 changes: 2 additions & 0 deletions xpra/scripts/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
make_progress_process,
load_pid,
X11_SOCKET_DIR,
may_block_numpy,
)
from xpra.scripts.config import (
InitException, InitInfo, InitExit,
Expand Down Expand Up @@ -359,6 +360,7 @@ def enforce_server_features() -> None:
"windows": "xpra.server.mixins.window,xpra.server.source.windows",
"rfb": "xpra.net.rfb,xpra.server.rfb",
})
may_block_numpy()


def make_monitor_server():
Expand Down

0 comments on commit 76d46ec

Please sign in to comment.