1

My understanding is that historically, the python Interpreter counted lines of code executed and switched threads after a fixed amount. This was then changed to being time dependent.

What I am trying to figure out is how is the time checked for the current threads running duration? Does time duration get called after every line is executed?

3
  • See github.com/python/cpython/blob/… for the implementation. Looks like there's a separate unlocking thread. Commented Jun 3, 2024 at 13:24
  • 1
    It has never been lines of code executed - that's not something the interpreter can easily access. Instead, it has traditionally been the number of bytecode instructions executed, with the default value being 100 as I recall (but I'm sure that value has changed over the years, and has always been adjustable via the sys module). With the change to a time-based thread switch interval, I would guess that the check is still in the same place, at the top of the bytecode-executing loop, but I couldn't find it in a quick look. Commented Jun 3, 2024 at 13:39
  • If you check it every time a byte code operation is executed, isn't that highly inefficient? Commented Jun 3, 2024 at 22:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.