Mark Hammond added the comment:

I've a few reservations here:

* CoInitialize will load a number of COM DLLs into the process, which isn't 
free and will have some memory and performance costs for programs that don't 
use COM. I see around 10 such DLLs loaded.

* pythoncom uses sys.coinit_flags because some COM objects simply don't work 
with the wrong apartment model. IOW, it is the objects you want to use on a 
particular thread that dictates the model you should use for that thread. Thus 
scripts written to interact with a particular COM object could set this flag 
before importing pythoncom so the correct threading model is setup. If this is 
done at Python startup, the script has lost the chance to influence this - 
insisting that Python be run with a particular set of flags for the script to 
work sounds painful.

* pythoncom defaults to COINIT_APARTMENTTHREADED as the apartment threading 
model is a special snowflake - if you need to use apartment model objects, the 
main thread *must* be apartment threading (even though other threads can use 
free threading.) COM objects with a UI (eg, MSOffice, IE) typically required 
apartment threading. Most new objects probably allow free threading, but I 
think we want to be careful about defaulting to a model that might avoid common 
objects from being used without an obscure command-line param.

* This may well break things like pythonwin until they also grow support for 
the new param - but new params for GUI applications somewhat suck as people 
tend to start them from an icon instead of the command-line.

* Each thread that wants to use COM must also make this call. If *any* object 
you want to use uses apartment model threading, then you really have no choice 
other than to init the main thread with this model - but you are then free to 
spin up other threads using free-threading, and life is good. So to make this 
sane, you really want to expose CoInitialize to Python code so new threads can 
do the right thing. So in this case, I wonder why we don't just expose it and 
let it be called manually?

IOW, it seems the potential risks of this outweighs the cost of requiring it to 
be called manually in a controlled way.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27417>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to