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
Asyncio #1318
Asyncio #1318
Conversation
This looks amazing! A few questions/notes:
|
@fzumstein Thanks - I fixed |
awesome! Here are my thoughts:
|
@fzumstein in this PR Excel still synchronously calls |
Cool, this fixed it. There one more issue though: When you open |
I've pushed a fix for that but it's a bit messy. When you pass a COM object to another thread Alternative would be to pass the address / sheet / pid / &c. as parameters as a special case, but I think this helps document the odd behaviour for the next time someone hits COM bugs. P.S. I accidentally reformatted udfs.py |
There's another issue I found: when you have many UDFs lined up, it does not manage to recalculate them all. See attached test case (should be added to the test actually). Change
See #881 for how it was fixed back then. |
I've added your stress test to On top of that, the I've kept the retry mechanism from #881 - it just lives here instead. I've added the ...finally, for another time it'd be nice if |
awesome! I'll give it some thorough testing again over the next days and let you know |
Few more observations/questions/suggestions:
|
@fzumstein ok addressed all of the above - although I'm pretty sure the first issue was always there as there wasn't a retry loop around It'd be nice if the Also, it turns out Asynchronous support is not available for IDispatch or for interfaces that inherit IDispatch. so will have to keep the |
great stuff! I'll let you know as soon as I am done with testing! |
Here's something new I found: when you open
|
@fzumstein hm, I can't reproduce that on Excel 2019 / pywin32 227. Does it happen deterministically? If you've got time to help debug it, could you try setting the below somewhere in xlwings so it prints out lots of win32 debug info?
My best guess is that due to the load (your stack trace is on retry 4 + 13 + 4 + 28 + 1!) a COM call failed that has made Changing
...otherwise I can put a call to [EDIT] |
It's not deterministic in the sense that it always fails on a different amount of formulas. I am running this on a VM with restricted resources so might be coming from there. When I enable the two debugging statements, it usually doesn't fail as it's slowed down I guess. Only once it failed with these errors:
|
@fzumstein ah got it - I was adding a random backoff to stop DoSing Excel when I started to repro it. It turns out that Excel does use early binding; it uses the CLSID to look up the pre-compiled object in a map (vs. what I was doing - compiling a new object every call). I've made |
I think this gets very close now! As usual, i have some comments ;)
|
@fzumstein oh right, it didn't fix #1164 but now it does! Your comments there were right - it's a race condition as when the array is cleared it triggers a recalcuation of I'd also expect it to be slower in every case due to the fact it's now retrying - |
impressive!! I'll give this a few more days of testing and let you know if I find anything else or have more questions :) |
Ok one more thing: we should maintain compatibility with Python 3.6, currently I get:
|
@njwhite I see that asyncio changed quite a bit between 3.6 and 3.7 - do you have an idea how painful it is to make it compatible with 3.6? |
@fzumstein I've pushed changes for 3.6 compatibility. It works, but:
I appreciate the time you've put into testing this - I'm definitely still working on getting this over the line! |
@njwhite awesome! I'll give it another round of testing and let you know. I think messy code to some extent part of writing a library - even with 2.7 out of the picture ;) |
@njwhite unfortunately, this indeed reintroduced the |
I also got the |
…op compatibility
@njwhite can you please have a look at my commit? let me know what you think. This only makes |
@fzumstein I've tried your commit on 3.6 after clearing & rebuilding |
@njwhite sure I agree on Python 3.6. It's only going to be around for another 1.5 years anyways. I'll try to have this branch tested in the field before I merge, but other than that I think it's ready now? |
@fzumstein great! let me know how it goes - |
@fzumstein excellent! |
@njwhite sorry it took so long! I'll try to release to pip package tomorrow and the conda package a few days later. |
💥 this has now been released on PyPI |
Add support for async UDFs (i.e. coroutines - see
async_tests.xlsm
) and hopefully fix array issues.This should replace PR #1177 / fix #1164; the "disappearing arrays" happen because
clear_contents
is called successfully but the.formula_array =
line silently fails due to the COM object being bound to the wrong thread (I think) - leaving you with empty cells. This PR introduces theComRange
subclass to handle marshalling the.impl
objects correctly across threads.Lays the groundwork for native Excel async functionality.