You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
foriinrange(3):
thread . start_new_thread ( f , ( lambda : i ) )
I got 2,2,2
Probably I don't get well design principles, but isn't
it against thread consistency? (as long as threads does
not interact with each other, interlace doesn't matter).
This is a bug in your understanding of lambdas, not in how
threads work. More specifically, lambdas do late binding.
By the time the threads have actually started executing and
call the lambda, the name 'i' is bound to the value 2.
If you need early binding, then you should bind early:
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: