python - AttributeError: 'module' object has no attribute 'lock'
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Bleepage Open
--
Chapters
00:00 Python - Attributeerror: 'Module' Object Has No Attribute 'Lock'
00:46 Accepted Answer Score 3
01:05 Answer 2 Score 0
01:16 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
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Techno Bleepage Open
--
Chapters
00:00 Python - Attributeerror: 'Module' Object Has No Attribute 'Lock'
00:46 Accepted Answer Score 3
01:05 Answer 2 Score 0
01:16 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