Bob Gailer wrote:
> Roger Upole wrote:
>> Bob Gailer wrote:
>>   
>>> Tim Golden wrote:
>>>     
>>>> [Bob Gailer]
>>>>   
>>>>       
>>>>> OK. I don't know whether its running in a thread. I made no 
>>>>> changes that I'm aware of that would cause the change in 
>>>>> behavior. I will add the call to pythoncom.CoInitialize. I am 
>>>>> not familiar with this method.
>>>>>     
>>>>>         
>>>> This is one of those gotcha's of Win32 COM programming;
>>>> you can be happily using some code which runs fine. You
>>>> then drop it into a [web server / service / scheduled job]
>>>> and lo! you're now running in a thread.
>>>>   
>>>>       
>>> Yeah, but when I said it was working, it was working in the server! 
>>> Wednesday AM just fine. Wednesday afternoon suddenly not working fine. I 
>>> swear I didn't change anything!
>>>
>>> Is there some way my program can introspect? to see if it is in a thread?
>>> I'm not sure (and perhaps someone can advise) whether there's
>>> any harm in *always* calling CoInitialize!
>>>     
>>
>> Multiple calls to CoInitialize don't hurt anything.  However (and I should 
>> have
>> mentioned this before) you also need to call CoUninitialize yourself at the 
>> end
>> of the thread.
>>   
> As I mentioned in my response to Tim, the thread name is 
> "H:\apache2triad". Since this is a long-running python instance I'm not 
> sure how to tell that the thread has ended. Is there magic to detect 
> that? And what happens if CoUninitialize does not get called?

If CoUninitialize doesn't get called for each call to CoInitialize,
you can leak memory.  You should be fine if you call CoInit before you
start, and CoUninit when you're done processing.

                 Roger

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

Reply via email to