Re: Python Query: Related to locking a resource in a multithreadedenvironment

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Genellina

    #1

    Re: Python Query: Related to locking a resource in a multithreadedenvironment

    En Tue, 19 Aug 2008 15:58:11 -0300, Nils Oliver Kröger <NO_Kroeger@gmx .de>
    escribi�:
    My approach what be to write one class for reading and writing to the
    configuration and make that class thread-safe using the RLock.
    >
    Then you create one and only one instance of this class and let all your
    threads use (not import) that one instance.
    >
    You could achieve that "one and only one" either by having a main
    program which creates the instance and pass the reference to each thread
    via its __init__ or you implement the Configuration class as a singleton
    like this:
    >
    class Singleton(objec t): [...]
    >Add your methods for accessing as instance methods to this class and get
    the same instance of this class in each thread by calling
    Singleton.getIn stance().
    Singleton.getIn stance() is so "javaistic" ... :)
    Actually there is no need for all of that; just define the RLock at the
    global scope in a module.
    Don't feel bad by using a "global" name - remember that a Python module
    acts as a named singleton. Defining an object at module scope is
    equivalent to defining an instance attribute in your Singleton class.

    --
    Gabriel Genellina

Working...