-
-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
race condition with multiple numpys in a single shell #3483
Comments
This could be solved in xpra by wrapping all numpy imports with an indirection layer, but that's not an elegant solution. Shouldn't this issue be solved by numpy itself? (builds without openblas don't have this issue) |
In any case, this issue has absolutely nothing to do with the html5 client so I have transferred it. |
Yes, probably this is an issue which should be solved in (thanks for moving the issue) |
I created an issue here: numpy/numpy#21223 |
As per the issue above, the fix should come from upsteam Python, or a band-aid in numpy. |
I am now also seeing this error with Fedora 36. |
@jhgoebbert I am unable to test this properly on my non-nvidia laptop, but the commit above should fix this issue. |
Great! Thank you for the fix. |
I had missed some that were loaded from xpra/xpra/client/gl/gl_window_backing_base.py Lines 1064 to 1065 in 4fbaf2c
And perhaps this is related to the memory leak in #3504. See also #3515 |
also add notes where we import pycuda to explain why it is safe to do so
Not fixed.
|
Not seen since. |
Seen today:
|
Anyone seeing this issue, please try with the latest version 6 or later.
(ie: just before or after |
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
Got this one today:
So the commit above adds locking in the X11 OpenGL context path. The big problem is that doing any kind of locking in the UI thread is bad.. |
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
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
The commits above does just that via: I am closing this ticket because I am reasonably confident that the underlying bug is now fixed, even if the solution is not ideal (blocking in the main thread...). |
coming from the posix gl context calling 'get_context_info'
Minor updates:
|
As part of fixes for Fedora 40 which fails to build And I think I found the culprit: File "/usr/bin/xpra", line 20, in <module>
sys.exit(main(sys.argv[0], sys.argv))
File "/usr/lib64/python3.10/site-packages/xpra/scripts/main.py", line 139, in main
return run_mode(script_file, cmdline, err, options, args, mode, defaults)
File "/usr/lib64/python3.10/site-packages/xpra/scripts/main.py", line 522, in run_mode
return do_run_mode(script_file, cmdline, error_cb, options, args, full_mode, defaults)
File "/usr/lib64/python3.10/site-packages/xpra/scripts/main.py", line 614, in do_run_mode
return run_client(script_file, cmdline, error_cb, options, args, mode)
File "/usr/lib64/python3.10/site-packages/xpra/scripts/main.py", line 1450, in run_client
app = get_client_app(cmdline, error_cb, opts, extra_args, mode)
File "/usr/lib64/python3.10/site-packages/xpra/scripts/main.py", line 1619, in get_client_app
app = get_client_gui_app(error_cb, opts, request_mode, extra_args, mode)
File "/usr/lib64/python3.10/site-packages/xpra/scripts/main.py", line 1691, in get_client_gui_app
app.init_ui(opts)
File "/usr/lib64/python3.10/site-packages/xpra/client/gui/ui_client_base.py", line 235, in init_ui
self.init_opengl(opts.opengl)
File "/usr/lib64/python3.10/site-packages/xpra/client/gtk3/client_base.py", line 1269, in init_opengl
self.opengl_props, gl_client_window_module = get_gl_client_window_module(enable_opengl)
File "/usr/lib64/python3.10/site-packages/xpra/client/gl/window.py", line 61, in get_gl_client_window_module
props, window_module = test_window_module(module_name, force_enable)
File "/usr/lib64/python3.10/site-packages/xpra/client/gl/window.py", line 70, in test_window_module
mod = import_module(f"xpra.client.gl.gtk3.{module_name}_window")
File "/usr/lib64/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/lib64/python3.10/site-packages/xpra/client/gl/gtk3/native_window.py", line 8, in <module>
from xpra.client.gl.gtk3.drawing_area import GLDrawingArea
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/lib64/python3.10/site-packages/xpra/client/gl/gtk3/drawing_area.py", line 11, in <module>
from xpra.client.gl.backing import GLWindowBackingBase
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/lib64/python3.10/site-packages/xpra/client/gl/backing.py", line 16, in <module>
from OpenGL.error import GLError
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/lib/python3.10/site-packages/OpenGL/error.py", line 164, in <module>
from OpenGL import acceleratesupport
File "<frozen importlib._bootstrap>", line 1078, in _handle_fromlist
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/usr/lib/python3.10/site-packages/OpenGL/acceleratesupport.py", line 8, in <module>
import OpenGL_accelerate So I am now very hopeful that the two commits above will finally catch the last of the threaded loading of the numpy module. |
including a better name for the subsystem and the full backtrace from both call sites
Reproduced with MS Windows shadow server here: #4287 (comment) : ie: $ python3.12
Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 14.0.1 20240411 (Red Hat 14.0.1-0)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from xpra.util.thread import start_thread
>>> from xpra.util.env import NumpyImportContext
>>> n=NumpyImportContext("foo", False)
>>> n.__enter__()
>>> def ni():
... n2=NumpyImportContext("foo2", False)
... n2.__enter__()
...
>>> start_thread(ni, "goo")
<Thread(goo, started 139833305466560)>
>>> 2024-07-06 16:05:40,864 debug enabled for ['threading', 'util']
2024-07-06 16:05:40,864 numpy lock was already acquired from:
2024-07-06 16:05:40,864 File "/usr/lib64/python3.12/threading.py", line 1030, in _bootstrap
2024-07-06 16:05:40,865 self._bootstrap_inner()
2024-07-06 16:05:40,865 File "/usr/lib64/python3.12/threading.py", line 1073, in _bootstrap_inner
2024-07-06 16:05:40,865 self.run()
2024-07-06 16:05:40,865 File "/usr/lib64/python3.12/threading.py", line 1010, in run
2024-07-06 16:05:40,865 self._target(*self._args, **self._kwargs)
2024-07-06 16:05:40,865 File "<stdin>", line 2, in ni
2024-07-06 16:05:40,865 failed to acquire it again from:
2024-07-06 16:05:40,865 File "/usr/lib64/python3.12/threading.py", line 1030, in _bootstrap
2024-07-06 16:05:40,865 self._bootstrap_inner()
2024-07-06 16:05:40,865 File "/usr/lib64/python3.12/threading.py", line 1073, in _bootstrap_inner
2024-07-06 16:05:40,865 self.run()
2024-07-06 16:05:40,865 File "/usr/lib64/python3.12/threading.py", line 1010, in run
2024-07-06 16:05:40,865 self._target(*self._args, **self._kwargs)
2024-07-06 16:05:40,865 File "<stdin>", line 3, in ni
Exception in thread goo:
Traceback (most recent call last):
File "/usr/lib64/python3.12/threading.py", line 1073, in _bootstrap_inner
self.run()
File "/usr/lib64/python3.12/threading.py", line 1010, in run
self._target(*self._args, **self._kwargs)
File "<stdin>", line 3, in ni
File "xpra/util/env.py", line 226, in xpra.util.env.NumpyImportContext.__enter__
RuntimeError: the numpy import lock is already held by 'foo2'! |
Today with xpra 5.0.11: 2024-11-22 16:54:47,175 cannot load nvenc (nvenc encoder)
Traceback (most recent call last):
File "/usr/lib64/python3.13/site-packages/xpra/codecs/loader.py", line 82, in codec_import_check
ic : ModuleType = __import__(class_module, {}, {}, classnames)
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "xpra/codecs/nvidia/nvenc/encoder.pyx", line 19, in init xpra.codecs.nvidia.nvenc.encoder
from xpra.util.objects import AtomicInteger, typedict
File "/usr/lib64/python3.13/site-packages/xpra/codecs/nvidia/cuda_context.py", line 32, in <module>
from pycuda.driver import (
...<4 lines>...
)
File "/usr/lib64/python3.13/site-packages/pycuda/driver.py", line 7, in <module>
import numpy as np
File "/usr/lib64/python3.13/site-packages/numpy/__init__.py", line 130, in <module>
from numpy.__config__ import show as show_config
File "/usr/lib64/python3.13/site-packages/numpy/__config__.py", line 4, in <module>
from numpy.core._multiarray_umath import (
...<3 lines>...
)
File "/usr/lib64/python3.13/site-packages/numpy/core/__init__.py", line 53, in <module>
del os.environ[envkey]
~~~~~~~~~~^^^^^^^^
File "<frozen os>", line 732, in __delitem__
KeyError: 'OPENBLAS_MAIN_FREE' |
I came across the following error while loading xpra:
After digging through the code I come to the following conclusion:
In
numpy/core/__init__.py
the environment variable 'OPENBLAS_MAIN_FREE' is set in line 19 if not existant and removed (if set in line 19) in line 52.To my understanding, this can result in a race condition if two numpys are initialized at the same time (by two threads) in the same shell.
It might be an answer to the error shown above.
The text was updated successfully, but these errors were encountered: