Another random comment re CoInitialize in servers...

Depending on your requirements, you may be better off with:

try:
  pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
except pythoncom.com_error:
  # already initialized.
  pass

(and as per Roger's comments, adding a flag to handle CoUninitialize).  That
way, you are more likely to get a COM object that can be shared across
multiple threads (eg, grabbing a shared ActiveDirectory connection), and
also handle the possibility someone else has beaten you to the Initialize
using different flags (a distinct possibility in a "plugin" style server
environment.)  Also, many server environments, such as Zope and I guess
Apache, use some kind of thread-pool mechanism.  Threads are often started
early, and only terminated as the process terminates (or whenever the server
feels the need to recycle threads for whatever reason).  For this reason, I
admit that not all code I write ensures CoUninitialize() is always called,
even though I should :)

Mark

<<attachment: winmail.dat>>

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to