question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Thread local has no attribute _current_plan

See original GitHub issue

I’ve been seeing an error in 7.0.0b3 resulting in the error AttributeError: '_thread._local' object has no attribute '_current_plan'. Looking through a git blame seems to point to https://github.com/cupy/cupy/commit/b150b89701fa51bf218765bf3c280a77b20e82bf which introduced a thread-local variable to hold the current plan. If I’m reading correctly (I’m not that familiar with Cython) it looks like variable gets initialized during module initialization. This means that any new threads created by the user do not have the _current_plan field (though they do have the _thread_local variable).

It looks like the intention of the code may have been to set a “default” value to the thread local _current_plan that could then be overwitten in a thread-local way. But that is not how Python thread local works (and I’m not aware of a way to make it work like that without adding a proxy object around it).

Can someone confirm the intention of the code, and whether a proxy object is an acceptable solution? If so I wouldn’t mind putting together a PR.

Conditions:

  • CuPy 7.0.0b3. Does not repro in 7.0.0b1.
  • Linux PPC64le
  • CUDA 9.2.148

Sample stacktrace output:

  File ".../conda/envs/myenv/lib/python3.6/site-packages/cupy/fft/fft.py", line 573, in fftn
    func = _default_fft_func(a, s, axes)
  File ".../conda/envs/myenv/lib/python3.6/site-packages/cupy/fft/fft.py", line 449, in _default_fft_func
    curr_plan = cufft.get_current_plan()
  File "cupy/cuda/cufft.pyx", line 16, in cupy.cuda.cufft.get_current_plan
  File "cupy/cuda/cufft.pyx", line 22, in cupy.cuda.cufft.get_current_plan
AttributeError: '_thread._local' object has no attribute '_current_plan'

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
elliottslaughtercommented, Aug 28, 2019

If the new threads do see _thread_local exists, it should also have the _current_plan attribute. The code path ensures that.

Like I said before, I don’t know about Cython, but at least in regular Python, this is not the semantics of thread-locals:

Python 2.7.16 (default, Jun 25 2019, 20:56:45) 
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import threading
>>> a = threading.local()
>>> a.x = 1234
>>> a.x
1234
>>> def print_a():
...     print a.x
... 
>>> t = threading.Thread(target=print_a)
>>> t.start()
>>> Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Users/elliott/.brew/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/Users/elliott/.brew/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "<stdin>", line 2, in print_a
AttributeError: 'thread._local' object has no attribute 'x'

I.e. a value set in the main thread will not be inherited by child threads. I do not know of a way (short of proxy objects) to achieve what the code currently seems to be doing.

1reaction
elliottslaughtercommented, Aug 30, 2019

Confirmed that the fix works in our original code base. Thanks all!

Read more comments on GitHub >

github_iconTop Results From Across the Web

'thread._local' object has no attribute - python - Stack Overflow
local ()) will show you the methods and attributes that do exist - value is not among them. If you are attempting to...
Read more >
'thread._local' object has no attribute 'value' error · Issue #13353
I am loading a model from an hdf5 file with using keras.models.load_model. when i try to predict using that model the following error ......
Read more >
AttributeError: '_thread._local' object has no attribute 'value'
I'm using keras 2.3.1, tensorflow 2.0.0, python 3.6, linux Mint 19.2 Cinnamon. My project is based on Waitress, so I can't use “threaded=False”....
Read more >
AttributeError: 'thread._local' object has no attribute '_scheduled'
This is simply a note for anybody else who may come across this error when trying to run web2py's scheduler - it works...
Read more >
NUnit Tutorial: Parameterized Tests With Examples
ThreadLocal <IWebDriver> driver = new ThreadLocal<IWebDriver>(); ... Step 3 – We have not used the SetUp attribute as the steps being ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found