How do I do time.sleep in certain thread in Python?

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

Was this solution helpful to you?

Other answers

Simply put a thread safe function should work the same in a threaded environment and a non threaded environment

Louie Hull

Just Added Q & A:

Find solution

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.