What is thread safety in Python?
-
-
Answer:
By thread-safety people usually mean whether a piece of code is re-entrant or not. That means if a function can be safely called again before the earlier function call has returned. Consider the append method of a Python List. If I have a List l = [1, 2, 3], can I safely call l.append(4) and l.append(5) from two different threads and get [1, 2, 3, 4, 5] (or [1, 2, 3, 5, 4]) in return? If yes, then the code is thread-safe. When people talk about Python's thread-safety in general, they mostly mean whether Python's basic data-structure operations are reentrant or not. Python's List data structure in the CPython implementation is, indeed, thread-safe. The same guarantee doesn't hold for other implementations. More here - http://en.wikipedia.org/wiki/Reentrant_code
Baishampayan Ghose at Quora Visit the source
Other answers
Simply put a thread safe function should work the same in a threaded environment and a non threaded environment
Louie Hull
Related Q & A:
- What are the common usage of python programming language?Best solution by quora.com
- What is the difference between a static method and class method in Python?Best solution by pythoncentral.io
- What does {!r} mean in Python?Best solution by Stack Overflow
- What questions will best assess workers' perceptions of health and safety at their workplace?Best solution by sciencedirect.com
- What's better choice considering durability and safety: Suzuki alto or Chery QQ?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.