-
-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delayed loading of npsupport #333
Comments
I also thought a situation like your issue was problematic. I didn't really have a problem with it because I don't use the Recently I have been working with restore test code(see #267, #298 and other issues/PRs).
As shown in Currently, regardless of whether Therefore, I think a better approach is that What are your thoughts? |
@junkmd tricky to import At the moment, the public functions of npsupport all contain a check for
This would make importing This is not ideal for backwards compatibility as scripts that were previously using numpy automatically would now have to enable support explicitly. However, I think that if we were to modify Thoughts? It would also be nice to get some perspective from @vasily-v-ryabov or @cfarrow, so we know if this change will get accepted if I implement it... |
Perhaps a correction, safearrays should not behave differently if you have numpy installed. This should only happen if you use the I'm in favor of replacing the import-time checks in npsupport with a |
Thanks, @cfarrow, but just to be clear, does that mean you would support a breaking change where |
I think the cleanest way to handle it is to allow that code to fail with a helpful error message if This will break backwards compatibility, and therefore would warrant a major version bump. |
Ok, I will have a look into making this work. It might still be possible to get |
Thank you guys for replies and opinions. I completely agree that it is better to do things explicitly. However, backward compatibility is the only problem I had, and I didn't want developers to experience the sadness of not being able to use the API as they used to. If calling a function at anywhere of the module makes they behave the same as before, that's fine. The project that using |
If there is a "pure python" default that works, then a warning would be appropriate. For the future, another option is to not assume a ndarray but instead check for a buffer. This would allow comtypes to handle a variety of array types efficiently. (I'm not quite sure how to do that, but it would be fun to figure out.) |
I agree with the major version update. Look at the history, it has only been revision updates for the last 8 years! |
I would be willing to help repair the tests that use |
@vasily-v-ryabov @bennyrowland I propose to release This purpose is to prevent developers from using |
Hi all, I started working on this project this morning and began with running the tests on the latest master branch using unittest output
Does anybody know anything about these errors, is this an environment / numpy version issue on my end (I am running 1.23.1) or are these tests failing for others? Do these issues need fixing before making any other changes to numpy interop? |
It is probably required registering |
Yep, I figured something like that would probably be the case - I have some ideas about trying to fake that but that will have to wait for another time. It is the other errors that I have been looking at. On closer inspection, the problems seem to relate to creating a numpy array of |
The numpy code in comtypes got a lot of attention in February. It might be worth checking if one of those changes broke the tests. FWIW, |
Well, that was my last contribution, so it could well be at fault :-). I think that the type code |
@cfarrow, so I have dug a little deeper into the "<P" typecode issue and it is definitely not related to #239, I rolled back before that commit and still see the issue. The problem seems to be that ctypes POINTER instances appear to support the PEP3118 Buffer Protocol, but actually are non-compliant, so for example if we run:
So numpy, when trying to create an array from So I guess this issue might have to be raised with ctypes? |
Guys I agree that numpy related changes could be a major version update to 1.2.0. So it will shift the end of Py2.7 support to 1.3.0 next year. |
Ok, a little bit more information: it looks like this came in with np 1.15.0 which changed the way the PEP3118 buffer protocol was used to create arrays, see numpy/numpy#11150. I think fixing this issue is way outside of our scope, creating numpy arrays from safearrays of ints, floats, bools etc. is all fine, it is only creating them from c_void_p that creates the problem, which is an unlikely use case in practice. I suggest we put this test on the skip list with an explanation - anyone that needs it fixing is likely to have a better idea than I do of how to do it. The other issue, regarding VARIANT_BOOL, seems more like a I have implemented a simple fix for npsupport being opt-in, basically if you don't call I think we can reasonably identify I will put together a PR soon so you can comment directly on the code, one thing that I did wonder about is whether we want to look at having multiple test environments (perhaps with tox) so that we can have an env with numpy installed and one without, with tests expecting different results in the different envs. We can simulate that to a certain extent by calling or not calling |
Nice diagnosis. Regarding numpy vs buffers, I think we'd want to support buffers in the long run, but can get there through updating the numpy support. I think we'll want multiple environments for testing eventually. If the plan is to generalize from numpy to buffers, however, it may not be worth the short-term overhead to do this solely for numpy support. |
I think we will still need numpy support for the |
True. If we want to test for unintended interactions, multiple test environments will be needed. |
@bennyrowland Since #337 and #343 have been merged, I will close this issue as resolved. If the issue remains, please re-open. |
I have been implementing some COM servers using comtypes, which are generally working very well. The design of the system is such that individual processing operations are provided by each COM server and are launched from a client GUI. In order to keep the GUI thread responsive, the servers each have a second "worker" thread to do their processing, the main thread only handles the COM interactions.
One of the issues that I have been confronting is start-up times for the server application, as this necessarily blocks the client software. This seems to be mainly caused by import times for the various libraries required, and so I have arranged things so that most libraries are imported by the worker thread rather than the main thread - however the most significant remaining library is numpy. I use this for processing, but it is not necessary to have the comtypes numpy interop behaviour. However, because numpy is installed, comtypes insists on importing it at startup, doubling the overall time to launch for a COM server. Do we think it would be possible to modify the way that npsupport is imported, either allowing it to be turned off completely, or even better to allow it to be loaded independently, i.e. import comtypes without it, starting up a server very fast, then import comtypes.npsupport (or call a function like comtypes.enable_np) to switch over to supporting it afterwards?
The text was updated successfully, but these errors were encountered: