Sharing database connection from C to Python

Daniel Dittmar daniel at dittmar.net
Wed Feb 1 16:16:45 EST 2006


dgiagio at gmail.com wrote:
> I'm developing an application using the C language and Python for it's
> plugins. The C program connects to a MySQL database and keeps that
> connection active. Is it possible to 'share' this connection with the
> Python plugins? If so, is there a "standard" way to do that?

There is no simple way as MySQL connections in Python are Python 
extension objects. You'll probably have to use a custom MySQL driver.

Either create the session in C and add a constructor to the python to 
create a MySQL connection object from that handle or pointer

Or add a method to the Python MySQL object to get the handle and 
pointer. Create all database connections in Python (precise: using the 
Python API from C), get the handle and pointer to use it from C, pass 
the original session to plugins.

Daniel



More information about the Python-list mailing list