B
B
beduin012018-05-19 14:39:20
Python
beduin01, 2018-05-19 14:39:20

At what point does GIL put threads to sleep?

According to the documentation, the GIL wakes/puts the threads to sleep at the point in time when the threads do not touch any shared data. And right there it is written that he does this every 5ms. The question is how does it all fit?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2018-05-19
@beduin01

The GIL does not sleep or wake up threads. The GIL is a lock used by interpreter system threads to ensure that two or more threads are not running at the same time. The interpreter thread calls cv_wait on the GIL with a timeout of 5 milliseconds. If the GIL is not released within 5ms, the thread will set the gil_drop_request variable and call cv_wait again. The thread owning the GIL periodically checks the state of the gil_drop_request variable and releases the GIL if it is set. The thread also releases the GIL on any I/O operation.

D
Dimonchik, 2018-05-19
@dimonchik2013

https://www.youtube.com/watch?v=AWX4JnAnjBE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question