Skip to content
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

Failed to get random numbers to initialize Python #1116

Open
InariInDream opened this issue Jul 9, 2024 · 0 comments
Open

Failed to get random numbers to initialize Python #1116

InariInDream opened this issue Jul 9, 2024 · 0 comments

Comments

@InariInDream
Copy link

OS: Windows 10 Pro, Version 21H2 (Build 19044.1889)
VSCode version: 1.60.0
CodeLLDB version: 1.10.0
Compiler: Clang 12.0.5 (from Android NDK r23)
Debuggee: aarch64-linux-android (using DWARF debug info)

Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python Python runtime state: preinitialized

I found the cause of this problem on websites. This answer pointed out that it can be easily reproduced on the Windows platform,

Python 3.8.10 (...) [MSC v.1928 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> from subprocess import Popen
>>> p = Popen([sys.executable, '-c', 'print("hello world")'], env={
...     'PYTHONPATH': ''
... })
Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python
Python runtime state: preinitialized

and many other open-source projects also have this issue.

I found the issue in the code within the plugin’s folder,

<vscode_extension_path>/vadimcn.vscode-lldb-1.10.0/lldb/lib/ctypes/util.py : 289
 try:
     with subprocess..Popen(['/sbin/ldconfig', '-p'],
                                           stdin=subporcess.DEVNULL,
                                           stderr=subprocess.DEVNULL,
                                           stdout=subprocess.PIPE,
                                           env={'LC_ALL': 'C', 'LANG': 'C'} as p:
          res = re.search(regex, p.stdout.read())

but strangely, it seems to be a file from the ctypes library. However, it must be called somewhere for the above error to occur.
Even after modifying all instances of subprocess.Popen() in the Python scripts and adding print statements to log each call, the plugin still throws an error, and I cannot see my logs. Does this mean that the plugin’s functionality is loaded only from the DLL? If so, can anyone provide a method for rebuilding, or should I open a new PR?
Steps to reproduce:

  1. Start a remote debugging session with CodeLLDB on an Android device. (PC is Windows)
  2. Observe the fatal Python error as described above.
Verbose log
  
Since the plugin is running on a machine from which content cannot be copied, it is difficult for me to provide complete log information. Therefore, I will manually type a few log entries near the errors here.
[DEBUG codelldb::debug_session] Debug event: 0000028790DC65D0 Event: broadcaster = 0000028791708C18 (lldb.target), type = 0x00000001 (breakpoint-changed), data = {bkpt: 6 type: locations removed}
[DEBUG codelldb::debug_session] Debug event: 000002879061FEE0 Event: broadcaster = 00000287919E8D38 (lldb.process), type = 0x00000001 (state-changed), data = { process = 00000287919E8D10} (pid = 15176), state = exited}
[DEBUG codelldb::dap_codec] <-- {"seq":89,"type":"event","event":"output","body":{"category":"console","output":"Process exited  with code1.\n"} }
Fatal Python error: _Py_HashRandomization_Init: failed to get random numbers to initialize Python Python runtime state: preinitialized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant