python - Does threading.local use locks for access? -


is there lock.acquire/release being done under covers in following statement:

my_thread_local = threading.local() my_thread_local.some_value = 1 

how one:

local_variable = my_thread_local.some_value 

only if fallback implementation in use.

if thread-local storage isn't otherwise provided (that is, if py_have_native_tls not defined when interpreter compiled), implementation used involves explicit locking.

on platforms proper native implementation, there's no need python runtime emulate feature, , no need locking @ python runtime layer.

as of writing (in july 2017), fallback implementation was removed development branch of python 3 (which no longer has thread module beos or other obscure operating systems formerly supported). thus, on future releases of python 3, native version of thread-local storage always in use when threading available @ all.


flowchart:

  • are on python 2.x?
    • are on windows? native thread-local storage available.
    • are on non-windows platform? python using locking-based implementation.
  • are on python 3.1 or later?
    • are on windows? native thread-local storage available.
    • are on modern linux, macos, or platform implements posix threads? native thread-local storage available.
    • are on non-windows platform doesn't support pthreads api? you either won't have threading support @ all, or thread-local storage involve locking.

(python 3.0 intentionally not covered here: native thread-local storage implementations present in both 2.7 , 3.1 , later aren't present in 3.0 @ same spot in code they're hosted in other versions, , i'm not considering worth time dig down determine whether functionality had temporarily moved or if it's missing outright).


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -