[Zope] - pcgi and multi concurrent access

Jim Fulton jim@digicool.com
Thu, 21 Jan 1999 14:02:06 +0000


Service Informatique CHSR wrote:
> 
> >In the future, the application itself will be able to
> >handle multiple requests simultaneously.  This will be
> >especially emportant if there are requests that consume alot
> >of application time, like indexing large databases.
> i suppose this mean that with this new version of pcgi,
> one has to write thread-safe code (although I still have to
> lean what thread-safe code is :-)). For example, one wouldn't
> write this:
> 
> class MyData:
>     """give access to my data"""
>     def __init__(self):
>         self.curs=db.cursor() # shared data -- bad
>     def request0(self):
>         """list the table0 content"""
>         self.curs.execute("select * from table0")
>         return self.curs.fetchall()
>     def request1(self):
>         """list the table1 content"""
>         self.curs.execute("select * from table1")
>         return self.curs.fetchall()
> bobo_application=MyData()
> 
> One would write this instead:
> 
> class MyData:
>     """give access to my data"""
>     def request0(self):
>         """list the table0 content"""
>         curs=db.cursor()
>         curs.execute("select * from table0")
>         return curs.fetchall()
>     def request1(self):
>         """list the table1 content"""
>         curs=db.cursor()
>         curs.execute("select * from table1")
>         return curs.fetchall()
> bobo_application=MyData()
> 
> Am i right?

Right.

> (about the fact that one should write thread-safe code
> *now* to support the new pcgi way of doing)

Right.

> Of course, this code is just an example, it is not what i intend to do.

Note that the database in Zope 2.0 will make writing thread-safe
applications much easier.  This is because each application thread
will have a separate "connection" to the database and it's own
copy of objects. So for example, if the first version of MyData
above was changed to use a database object, it would be thread safe
(using the database that will be included in Zope 2).

Jim

--
Jim Fulton           mailto:jim@digicool.com
Technical Director   (540) 371-6909              Python Powered!
Digital Creations    http://www.digicool.com     http://www.python.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.