Webware 0.7/Singleton pattern

Ian Bicking ianb at colorstudy.com
Tue Jul 16 14:23:21 EDT 2002


On Tue, 2002-07-16 at 03:50, Alex Martelli wrote:
> Michael Bub wrote:
>         ...
> > WebApp built with Webware 0.7 (using Python 2.2 on a FreeBSD4.4
> > system), the second or third time the get_instance method is called,
> > the one instance that was created by the singleton seems to be
> > forgotten about (or rather, it seems as if the file that holds the
> > class definition was imported and used for the very first time) and
> 
> You may be serving hits in different processes -- that depends in
> part on how you're using Webware... it can be installed to work
> on top of CGI, and CGI by definition uses a new process each time.

Even when using the CGI adapter with Webware, you still only have one
process.  The CGI program starts, and then connects to the persistent
Webware AppServer.  (Unless you are using OneShot, which can introduce
all sorts of problems like this, since it does start new processes)

It might be a case of a module being imported under two names, e.g., if
/path and /path/context are both in sys.path, then when you do 
"from path.context import X" and "from context import X", you'll have
two copies of the X module, and then two singletons.

  Ian







More information about the Python-list mailing list