Thread safety in Python (Question how it works)
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: Hypnotic Puzzle2
--
Chapters
00:00 Question
01:13 Accepted answer (Score 1)
01:55 Thank you
--
Full question
https://stackoverflow.com/questions/3164...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #multithreading
#avk47
--
Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Puzzle2
--
Chapters
00:00 Question
01:13 Accepted answer (Score 1)
01:55 Thank you
--
Full question
https://stackoverflow.com/questions/3164...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #multithreading
#avk47
ACCEPTED ANSWER
Score 1
Locals are thread-safe as they are not shared between threads. All constants (variables you never write to from any thread) are thread-safe. If that's all you have, then yes, that's fine. Ensure the class members you are talking about are really not written from any other thread.
Check there are no underlying shared resources that might not be thread-safe, eg. if each thread is using the database connection object that may cause trouble, unless that object is specifically documented as being thread-safe.