Directly calling threaded class instance methods and attributes

Josiah Carlson jcarlson at uci.edu
Thu Oct 28 20:26:55 CEST 2004


Just <just at xs4all.nl> wrote:
> 
> In article <mailman.5624.1098986746.5135.python-list at python.org>,
> 
> FWIW, you don't need a global statement for globals you don't assign to, 
> so you don't need to declare lock global.

I was going to say that I did it for speed, and I could have sworn that
stating something was a global resulted in a fewer namespace lookups,
but testing does not confirm this (it actually refutes it). I guess this
says that I should be aliasing globals when I really care about speed,
making it...

>>> def goo(n):
...     global val2
...     _lock = lock
...     for i in xrange(n):
...         _lock.acquire()
...         val2 += 1
...         _lock.release()


...for a little bit faster (though the locking/unlocking will overwhelm
the actual time spent.

 - Josiah




More information about the Python-list mailing list