Need advice on multithreading problem

Gerhard Häring gerhard at
Tue Jun 4 11:55:20 EDT 2002

In article <adih99$rkm$1 at>, Aahz wrote:
> Gerhard Häring <gerhard at> wrote:
>>The problem is this: I have a C library with a function of the following
>>    def sqlite_exec(conn, sql, callback, arg1):
>>The only important parameter here is 'callback', it is a callback
>>function that you need to give to sqlite_exec. The callback function
>>will be called with the items sqlite_exec returns. If the callback
>>functions returns a value other than zero, sqlite_exec will stop its
>>On the Python side, I wanted to force this C library call into a
>>generator.  Which I did using a thread that's spawned for a new
>>sqlite_exec call and Queue.Queue.
> Is SQLite thread-safe?

If compiled with the right options, it is.

> Do you provide a thread-local conn?

No, but I can guarantee that the connection will only be accessed by one thread
at a time. I believe the current code already does guarantee that.

> Does sqlite_exec() return a brand-new cursor?

As you can see in the code, it doesn't return anything. All it does is call the
callback function. The implementation of my callback function writes to a
queue, and the fetchone/fetchmany/fetchall methods of Cursor read from the

> If the answer to any question is "no", your code is probably broken (haven't
> actually read it).

Thanks for commenting, but I did knew these basics of multithreading already.


More information about the Python-list mailing list