Issue #944 resolved

Jython: AttributeError: 'module' object has no attribute '_get_ident'

Anonymous created an issue

With the latest jythion trunk, the most recent CP trunk cannot run due to the following exception:

{{{ AttributeError: 'module' object has no attribute '_get_ident' }}}

In ThreadManager.acquire_thread

The following post offers a working solution:

Should the next fix be applied?

{{{ Index: cherrypy/process/ =================================================================== --- cherrypy/process/ (révision 2470) +++ cherrypy/process/ (copie de travail) @@ -537,7 +537,10 @@ If the current thread has already been seen, any 'start_thread' listeners will not be run again. """ - thread_ident = threading._get_ident() + try: + thread_ident = threading._get_ident() + except AttributeError: + thread_ident = threading.local() if thread_ident not in self.threads: # We can't just use _get_ident as the thread ID # because some platforms reuse thread ID's. }}}

Reported by lawouach

Comments (4)

  1. Robert Brewer

    I don't see how threading.local() identifies the thread:

    Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) 
    [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import threading
    >>> a = threading.local()
    >>> b = threading.local()
    >>> a is b
    >>> a == b

    Or am I reading the proposed fix wrong?

  2. Anonymous

    threading.local() creates a thread local variable, i.e. a variable that can hold different values for each thread.

    threading._get_ident is actually imported from the thread module in CPython, and the Jython counterpart has no use for it in the threading module, and since it is an implementation detail (starts with underscore), we don't import it in threading.

    The solution here is to use the function from its original place in the thread module, where Jython supports it: thread.get_ident().

  3. Log in to comment