yield, curry, mix-in, new.function, global, closure, .... what will work?

ecir.hana at gmail.com ecir.hana at gmail.com
Mon Apr 16 21:51:26 EDT 2007


I'm reading the docs now and I stumbled upon something:
section "15.3 threading -- Higher-level threading interface" mensions
a class "local", in which "... Thread-local data are data whose values
are thread specific. ..."

Does it mean, I can create global variables whose changing is thread-
safe?
More specific:

import threading

def change_i(arg):
    global k
    k.i = arg

def change_j(arg):
    global k
    k.j = arg

def changer():
    change_i('changed_i')
    change_j('changed_j')

def run(i='', j=''):
    global k
    k = threading.local()
    k.i = i
    k.j = j
    changer()
    i = k.i
    j = k.j
    return i, j

print run() == ('changed_i', 'changed_j')

Is this ok?




More information about the Python-list mailing list