OSX zeigt nicht die Namen von Fread-Thread-Python-Threads anPython

Python-Programme
Anonymous
 OSX zeigt nicht die Namen von Fread-Thread-Python-Threads an

Post by Anonymous »

Ich mache mit Python_gil = 0 auf macOS sequoia 15.7.

Code: Select all

thread = threading.Thread(target=lambda: time.sleep(10), name="test-thread")
thread.start()
< /code>
, aber ihre Namen würden nicht von OS angezeigt (beachten Sie die zweite Zeile, die dem Thread entspricht, ist leer): < /p>
$ ps -M 87266
USER     PID   TT   %CPU STAT PRI     STIME     UTIME COMMAND
burkov 87266 s032    0.0 S    31T   0:00.24   0:00.87 /Library/Frameworks/PythonT.framework/Versions/3.
87266         0.0 S    31T   0:00.00   0:00.00
Ich versuche, Namen manuell mit pThreads pthread_setname_np Anruf:
def set_thread_name(thread: threading.Thread, name: str):
"""Set the OS thread name using pthread_setname_np

Should be called after thread.start()!
"""
try:
libpthread_path = ctypes.util.find_library("pthread")
if libpthread_path:
libpthread = ctypes.CDLL(libpthread_path)
if hasattr(libpthread, "pthread_setname_np"):
pthread_setname_np = libpthread.pthread_setname_np
pthread_setname_np.argtypes = [ctypes.c_void_p, ctypes.c_char_p]
pthread_setname_np.restype = ctypes.c_int

# Get current thread ID
thread_id = thread.ident
pthread_setname_np(thread_id, name.encode('ascii', 'replace')[:15])
except Exception:
pass # Ignore failures

thread = threading.Thread(target=lambda: time.sleep(10), name="test-thread")
thread.start()
set_thread_name(thread, "test-thread")
< /code>
Wieder ohne Erfolg. Können Sie vorschlagen, wie ich das beheben kann?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post