This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mhammond
Recipients brett.cannon, eryksun, mhammond, paul.moore, steve.dower, tim.golden, zach.ware
Date 2016-06-30.01:00:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1467248414.82.0.789772821801.issue27417@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-06-30 01:00:15mhammondsetrecipients: + mhammond, brett.cannon, paul.moore, tim.golden, zach.ware, eryksun, steve.dower
2016-06-30 01:00:14mhammondsetmessageid: <1467248414.82.0.789772821801.issue27417@psf.upfronthosting.co.za>
2016-06-30 01:00:14mhammondlinkissue27417 messages
2016-06-30 01:00:11mhammondcreate