python - AttributeError: 'module' object has no attribute 'lock'
Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn
--
Music by Eric Matyas
https://www.soundimage.org
Track title: City Beneath the Waves Looping
--
Chapters
00:00 Question
01:08 Accepted answer (Score 3)
01:30 Answer 2 (Score 0)
01:46 Thank you
--
Full question
https://stackoverflow.com/questions/2982...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #multithreading #unittesting #types #attributeerror
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: City Beneath the Waves Looping
--
Chapters
00:00 Question
01:08 Accepted answer (Score 3)
01:30 Answer 2 (Score 0)
01:46 Thank you
--
Full question
https://stackoverflow.com/questions/2982...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #multithreading #unittesting #types #attributeerror
#avk47
ACCEPTED ANSWER
Score 3
Instead of thread.lock use thread.LockType:
>>> import threading, thread
>>> mylock = threading.Lock()
>>> type(mylock)
<type 'thread.lock'>
>>> thread.LockType
<type 'thread.lock'>
>>> type(mylock) is thread.LockType
True
But it is preferable to use isinstance():
>>> isinstance(mylock, thread.LockType)
True
ANSWER 2
Score 0
Use the isinstance() function instead.
>>> import threading, thread
>>> mylock = threading.Lock()
>>> type(mylock)
<type 'thread.lock'>
>>> isinstance(mylock, type(threading.Lock()))
True