[Python-Dev] PEP 550 v4 (original) (raw)
francismb francismb at email.de
Sat Aug 26 16:45:07 EDT 2017
- Previous message (by thread): [Python-Dev] PEP 550 v4
- Next message (by thread): [Python-Dev] PEP 550 v4
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi,
Multithreaded Code ------------------
In multithreaded code, context variables behave like thread locals:: var = newcontextvar() def sub(): assert var.lookup() is None # The execution context is empty # for each new thread. var.set('sub') def main(): var.set('main') thread = threading.Thread(target=sub) thread.start() thread.join() assert var.lookup() == 'main' it's by design that the execution context for new threads to be empty or should it be possible to set it to some initial value? Like e.g:
var = new_context_var('init')
def sub():
assert var.lookup() == 'init'
var.set('sub')
def main():
var.set('main')
thread = threading.Thread(target=sub)
thread.start()
thread.join()
assert var.lookup() == 'main'
Thanks, --francis
- Previous message (by thread): [Python-Dev] PEP 550 v4
- Next message (by thread): [Python-Dev] PEP 550 v4
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]