threads

15 views
Skip to first unread message

ff

unread,
Dec 10, 2009, 7:09:22 AM12/10/09
to CouchDB-Python
Hi, is python-couchdb thread safe? I'm wondering because so far I had
no problems, but today I've tried using it in web app doing many ajax
calls and many fail with strange errors in httplib. I wonder if this
is problem related to threads, since it's the only difference I've
found so far between all the other uses

Dirkjan Ochtman

unread,
Dec 10, 2009, 7:13:08 AM12/10/09
to couchdb...@googlegroups.com
What versions of couchdb-python and httplib2 are you using? There are
known problems with the latest release of httplib2, you may want to
revert to 0.4.0.

Cheers,

Dirkjan

Matt Goodall

unread,
Dec 10, 2009, 7:34:29 AM12/10/09
to couchdb...@googlegroups.com
2009/12/10 Dirkjan Ochtman <dir...@ochtman.nl>:
Last time I checked httplib2 was not thread safe, so python-couchdb
won't be either.

- Matt

ff

unread,
Dec 10, 2009, 8:06:59 AM12/10/09
to CouchDB-Python
On Dec 10, 1:34 pm, Matt Goodall <matt.good...@gmail.com> wrote:

> > What versions of couchdb-python and httplib2 are you using? There are
> > known problems with the latest release of httplib2, you may want to
> > revert to 0.4.0.
>
> Last time I checked httplib2 was not thread safe, so python-couchdb
> won't be either.

Yep, I'm digging into the code and I realize it. The main problem is
that it reuses the same Resource for each request. Transforming
self.resource into an accessor returning a fresh Resource each time
should fix it.

bye

Matt Goodall

unread,
Dec 10, 2009, 8:35:13 AM12/10/09
to couchdb...@googlegroups.com
2009/12/10 ff <fabio...@gmail.com>:
Also:

* httplib2 reuses existing connections from a cache. (Not sure if
that's the same as the "Resource" stuff you mentioned, I can't
remember the implementation now.)
* httplib2 optionally caches responses. The cache implementations
(filesystem, for instance) are not thread safe.

Even then, there's no guarantee that python-couchdb is thread safe.

I think you're **much** safer allocating a CouchDB connection to each
request. You could create a new Database instance or grab one from a
pool of existing Database instance to reduce initial connection
latency.

- Matt

Christopher Lenz

unread,
Dec 10, 2009, 10:49:15 AM12/10/09
to couchdb...@googlegroups.com
On 10.12.2009, at 14:35, Matt Goodall wrote:
> 2009/12/10 ff <fabio...@gmail.com>:
>> On Dec 10, 1:34 pm, Matt Goodall <matt.good...@gmail.com> wrote:
>>> Last time I checked httplib2 was not thread safe, so python-couchdb
>>> won't be either.
>>
>> Yep, I'm digging into the code and I realize it. The main problem is
>> that it reuses the same Resource for each request. Transforming
>> self.resource into an accessor returning a fresh Resource each time
>> should fix it.
>
> Also:
>
> * httplib2 reuses existing connections from a cache. (Not sure if
> that's the same as the "Resource" stuff you mentioned, I can't
> remember the implementation now.)
> * httplib2 optionally caches responses. The cache implementations
> (filesystem, for instance) are not thread safe.
>
> Even then, there's no guarantee that python-couchdb is thread safe.

For what it's worth, thread-safety was one of the goals I had in mind for the httplib branch.

Cheers,
--
Christopher Lenz
cmlenz at gmx.de
http://www.cmlenz.net/

Reply all
Reply to author
Forward
0 new messages