In Python for *nix, does time.sleep()
block the thread or the process?
This question is related to
python
multithreading
time
sleep
python-internals
Just the thread.
It will just sleep the thread except in the case where your application has only a single thread, in which case it will sleep the thread and effectively the process as well.
The python documentation on sleep doesn't specify this however, so I can certainly understand the confusion!
Just the thread.
Only the thread unless your process has a single thread.
it blocks a thread if it is executed in the same thread not if it is executed from the main code
Just the thread.
The thread will block, but the process is still alive.
In a single threaded application, this means everything is blocked while you sleep. In a multithreaded application, only the thread you explicitly 'sleep' will block and the other threads still run within the process.
It will just sleep the thread except in the case where your application has only a single thread, in which case it will sleep the thread and effectively the process as well.
The python documentation on sleep doesn't specify this however, so I can certainly understand the confusion!
it blocks a thread if it is executed in the same thread not if it is executed from the main code
Only the thread unless your process has a single thread.
The thread will block, but the process is still alive.
In a single threaded application, this means everything is blocked while you sleep. In a multithreaded application, only the thread you explicitly 'sleep' will block and the other threads still run within the process.
It will just sleep the thread except in the case where your application has only a single thread, in which case it will sleep the thread and effectively the process as well.
The python documentation on sleep doesn't specify this however, so I can certainly understand the confusion!
Process is not runnable by itself. In regard to execution, process is just a container for threads. Meaning you can't pause the process at all. It is simply not applicable to process.
It will just sleep the thread except in the case where your application has only a single thread, in which case it will sleep the thread and effectively the process as well.
The python documentation on sleep doesn't specify this however, so I can certainly understand the confusion!
Just the thread.
The thread will block, but the process is still alive.
In a single threaded application, this means everything is blocked while you sleep. In a multithreaded application, only the thread you explicitly 'sleep' will block and the other threads still run within the process.
Process is not runnable by itself. In regard to execution, process is just a container for threads. Meaning you can't pause the process at all. It is simply not applicable to process.
Source: Stackoverflow.com