Python, COM Servers, and Multi-Threading

Stefan Schukat SSchukat at dspace.de
Mon Nov 7 11:29:39 EST 2005


Hi, 

you get best performance if you make your servers local servers, since
then every
interpreter runs in ist own process. If you make it an inproc server you
synchronize
all threads/CPUs with the GIL. Even better multithreading support you
will get 
if you mark your server to run in an multithreaded apartment (MTA). 

e.g. 


class COMClass:
	_public_methods_ = [ 'Method', ... ]
	_reg_verprogid_ = "COMServer.COMClass.1"
	_reg_progid_ = "COMServer.COMClass"
	_reg_desc_ = "COMServer COMClass"
	_reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"
	_reg_class_spec_ = "win32com.servers.COMServer.COMClass"
	_reg_threading_ = "free"
# <--- Threading model
	_reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER
# <-- own exe


  Stefan

 

> -----Original Message-----
> From: python-list-bounces+sschukat=dspace.de at python.org 
> [mailto:python-list-bounces+sschukat=dspace.de at python.org] On 
> Behalf Of Carl Waldbieser
> Sent: Tuesday, October 11, 2005 12:46 AM
> To: python-list at python.org
> Subject: Python, COM Servers, and Multi-Threading
> 
> 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
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list