On 10/4/10 11:39 AM, Scott Pigman wrote:
I want to use the 64 bit version of python but run some code inside a
spawned process that uses the 32 bit version. Is there an official
way to do this, or can anybody make a recommendation about the
cleanest way to do this? If someone has a better solution to the
problem I describe below, I'd appreciate hearing that too. I'm using
python 2.7, but could go to 3.x if that has better support for this.
My program interacts with two different commercial libraries by using
ctypes to execute functions inside their DLLs. One library only
exists in a 32 bit version. The second library has both 64 and 32 bit
versions. The code was initially developed for a 32 bit platform, but
now I need to support a user on a 64 bit machine as well. I've
learned that ctypes can only interact with libraries which match the
version of python that is running --- 32 bit python can use 32 bit
DLLs, 64 bit python can use 64 bit DLLs, so when I'm running on a 64
bit machine with one 64 bit library and the other at 32 bits, I can't
use the 32 bit library.
I believe that the solution is to have both win32 and x64 versions of
python installed, and then execute the win32 code inside of a new
process which uses the win32 version of Python. I'm already using
multiprocessing to run that code inside a new process because the two
libraries have conflicts and need to run in separate memory space. If
I could just specify that I want the new process to use a different
version of the interpreter I think I'd be all set, but I don't see a
way of doing that.
You cannot use a Process() to do this, but you should be able to use Managers or
the other tools in the multiprocessing packages for communicating between the
processes.
http://docs.python.org/library/multiprocessing#module-multiprocessing.managers
There may be hidden assumptions in the code, though. I've never tried it myself.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
--
http://mail.python.org/mailman/listinfo/python-list