[Python-3000] is it easier to multithread ?

Josiah Carlson josiah.carlson at gmail.com
Fri Aug 1 02:16:55 CEST 2008


On Thu, Jul 31, 2008 at 8:18 AM, binaryjesus <coolman.guron at gmail.com> wrote:
> Is these any improvement in multi-threaded performance in the py3k
> scheduler over py2?
> >From what i know py2 runs only 1 (one) pythn thread at a time (refer 1
> below).  Another thing that i would like to see being included in
> python is auto-mutex like the java implementation. That would make my
> life much easier !!

Things have not changed with regards to Python's threading
implementation in py3k.

If you want auto-locking with function calls, there isn't a keyword
that you can just pass, but there are these magical things called
decorators that allow the easy creation of synchronized decorators...

import threading

_lock = threading.RLock()
def synchronized(fcn):
    def call(*args, **kwargs):
        with _lock:
            return fcn(*args, **kwargs)
    return call


Used like:

class foo:
    @synchronized
    def method(self, ...):
        #because of the synchronized decorator, this method is now
protected by a lock

 - Josiah


More information about the Python-3000 mailing list