Python, COM Servers, and Multi-Threading

C

Carl Waldbieser

I have been considering using Python and the Reportlab library for
generating PDF reports for the back-end of a web based application. The
application runs most of its background tasks on a dedicated server that is
Windows based (Win2K or Win2k3). The program that launches the tasks
requires a COM-based interface, so I wrote a Python COM server using Mark
Hammond's PythonCom libraries and import and run the reporlab modules from
there.

I had been reading up on Python and it's handling of the multiple threads,
specifically the Global Interpreter Lock (GIL). I got to wondering if a
multi-processor machine machine would be able to take advantage of its
extra processing power using this setup. I am guessing that the GIL is
global with respect to each instance of a running Python interpreter, so if
say 4 interpreters were running, a 4 processor machine would be able to
take advantage of this. However, I am not quite sure how launching my
reports via COM behaves-- if I launched 4 reports this way, would that be
like launching 4 seperate instances of the Python interpreter, or would it
be just a single instance, and therefore run into the limitations of the
GIL? If so, can anybody offer suggestions as to a design that would be
better able to take advantage of a multi-processor machine?

Thanks,
Carl Waldbieser
 
S

Steve Holden

Carl said:
I have been considering using Python and the Reportlab library for
generating PDF reports for the back-end of a web based application. The
application runs most of its background tasks on a dedicated server that is
Windows based (Win2K or Win2k3). The program that launches the tasks
requires a COM-based interface, so I wrote a Python COM server using Mark
Hammond's PythonCom libraries and import and run the reporlab modules from
there.
Have you selected a specific threading model for your COM server? This
will affect how hardware resource are allocated as well as how sharing
takes place between different uses.
I had been reading up on Python and it's handling of the multiple threads,
specifically the Global Interpreter Lock (GIL). I got to wondering if a
multi-processor machine machine would be able to take advantage of its
extra processing power using this setup. I am guessing that the GIL is
global with respect to each instance of a running Python interpreter, so if
say 4 interpreters were running, a 4 processor machine would be able to
take advantage of this. However, I am not quite sure how launching my
reports via COM behaves-- if I launched 4 reports this way, would that be
like launching 4 seperate instances of the Python interpreter, or would it
be just a single instance, and therefore run into the limitations of the
GIL? If so, can anybody offer suggestions as to a design that would be
better able to take advantage of a multi-processor machine?
I am certainly no expert on COM threading models, but I would suspect
that if you specify you want your COM server to be in-process then you
would get a per-process interpreter.

You also need to be aware that if you trigger this stuff with IIS then
the web server itself performs thread pooling and (I believe) allocates
only one process per "application", so this may defeat your desire to
use all four processors concurrently.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top