[Zope] threading and External Methods

Jim Fulton jim@digicool.com
Tue, 10 Aug 1999 08:00:39 -0400


Brian Hooper wrote:
> 
> Hi there -
> 
> Real simple question: Do I need to worry about threading when coding
> External Methods (in Zope 2)? 

Certainly.  Here are basic rules:

  - You don't have to worry about state of
    persistent objects (e.g. self). Persistent
    objects are inherently thread safe, since each
    thread has it's own copy.

  - You don't have to worry about state of immutable
    objects, as they can't be modified by multiple
    threads.

  - You do need to worry about global variables
    (e.g. module variables and shared instance
    variables defined in class statements) and
    mutable default arguments to functions and 
    methods.

> If I do have something that is not safe
> (for example, I want to os.system nslookup to check MX records)

Hm. Why is this not safe? This is definately pretty heavy.

> do I have to explicitly protect it somehow?

Yes.  This can be done with a simple lock object, or one of the
various modules distributed with Python.

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.