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 steve.dower
Recipients brett.cannon, eryksun, mhammond, nnemkin, paul.moore, steve.dower, tim.golden, zach.ware
Date 2016-06-30.15:58:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1467302294.43.0.958653586736.issue27417@psf.upfronthosting.co.za>
In-reply-to
Content
Mark:
> 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.

Very good point. Most of those should already be loaded in the OS, which reduces the cost, but it's still not free. Given some other work I've been trying to do to reduce footprint, this is definitely a step backwards :(

> This may well break things like pythonwin until they also grow support for the new param 

I expect that, which is why I'm only proposing it for 3.6 onwards. While adding support for a new major version of Python should be fairly cheap, it isn't entirely free and so it's the right time to add new complications.

> I wonder why we don't just expose it and let it be called manually?

Because that prevents us adding features to the core interpreter that require COM before a user could choose to initialize it. Also, that's the current state of the world, and this is a proposal to change it - hence I don't want to start with that as an assumption since it makes this whole discussion moot :)

Nikita:
> COM should be initialized on demand by C modules that need it. They might need STA or MTA, it's their choice to make.

And if the C module is the core interpreter (see issue26137 for an example of where this would be necessary)? If we require user code to initialize COM, this whole proposal is moot as that is the current state of the world and it does not require any changes to achieve.

> COM using apps are very likely to be GUI apps and need STA main thread. MTA by default makes no sense.

Fair point. CoInitializeEx defaults to MTA, and pythonwin follows this, while IronPython defaults to STA (since COM initialization is unavoidable in their context), so the default we should use is not obvious. But I will mention that there are plenty of ways that COM is useful without writing a GUI app, so I don't think we should assume that only GUI apps are going to use it.

> PS. AMSI ...

Your PS is basically answered in issue26137 - I want to keep the discussion of the merits of AMSI separate from this issue :)

Paul:
> It seems to me that core code that needs COM can use it by wrapping the code in CoInitializeEx(sys.coinit_flags)...CoUninitialize(). 

This doesn't work when COM objects have to be kept around. In the AMSI case, the threading model is irrelevant, but you need to keep reusing the same context for each call, which means you can't keep initializing COM (I tried it - it crashes, I believe because you get a new memory allocator and/or arena each time, but I didn't diagnose the crash thoroughly).


There may be a workaround for cases where we can't keep reinitializing COM (add a background non-Python thread and do all the calls from there), but the complexity is fairly high and the performance impact is greater. Worth investigating further, since the general feeling seems to be against change.
History
Date User Action Args
2016-06-30 15:58:14steve.dowersetrecipients: + steve.dower, mhammond, brett.cannon, paul.moore, tim.golden, zach.ware, eryksun, nnemkin
2016-06-30 15:58:14steve.dowersetmessageid: <1467302294.43.0.958653586736.issue27417@psf.upfronthosting.co.za>
2016-06-30 15:58:14steve.dowerlinkissue27417 messages
2016-06-30 15:58:13steve.dowercreate