Author kovid
Recipients Arfrever, asvetlov, bra, christian.heimes, flox, jcea, kovid, pitrou, r.david.murray
Date 2014-11-06.11:58:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Just FYI, a pure python2 implementation that monkey patches Thread.start() to set the OS level thread name intelligently.

        import ctypes, ctypes.util, threading
        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
                orig_start = threading.Thread.start
                def new_start(self):
                        name =
                        if not name or name.startswith('Thread-'):
                            name = self.__class__.__name__
                            if name == 'Thread':
                                name =
                        if name:
                            if isinstance(name, unicode):
                                name = name.encode('ascii', 'replace')
                            ident = getattr(self, "ident", None)
                            if ident is not None:
                                pthread_setname_np(ident, name[:15])
                    except Exception:
                        pass  # Don't care about failure to set name
                threading.Thread.start = new_start
Date User Action Args
2014-11-06 11:58:01kovidsetrecipients: + kovid, jcea, pitrou, christian.heimes, Arfrever, r.david.murray, asvetlov, flox, bra
2014-11-06 11:58:01kovidsetmessageid: <>
2014-11-06 11:58:01kovidlinkissue15500 messages
2014-11-06 11:58:00kovidcreate