I've been trying to look for ways to call my python script from my perl script and pass the database handle from there while calling it. I don't want to establish another connection in my python script and just use the db handle which is being used by the perl script. Is it even possible and if yes then how?
There answer is that almost all databases (Oracle, MySQL, Postgresql) will NOT allow you to pass open DB connections between processes (even parent/child). This is a limit on the databases connection, which will usually be associated with lot of state information.
If it was possible to 'share' such a connection, it will be a challenge for the system to know where to ship the results for queries sent to the database (will the result go to the parent, or to the child ?).
Even if it is possible somehow to forward connection between processes, trying to pass a complex object (database connection is much more the socket) between Perl (usually DBI), and Python is close to impossible.
The 'proper' solution is to pass the database connection string, username, and password to the Python process, so that it can establish it's own connection.
Can a db handle be passed from a perl script to a python script?