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
issue refreshing table return in excel while function well calculated #880
Comments
Get rid of all the wb/sht objects and pass your ranges as parameters |
thank you very much for your answer but it doesn't seem to work better. i can describe the situation more precisely : |
I am having similar problems. I have a sheet with a number of UDFs calling Numpy functions. On opening the spreadsheet some of the results show an error in the first item. If I recalculate everything with Ctrl-Alt-F9 some of the errors are fixed, but others appear elsewhere. If I select the functions individually and refresh with F2, Enter, they always return the correct result. Typical python code is shown below, and I have attached two screen-shots, both after a full-recalc.
|
Count me in as well. I have also encountered this problem that dynamic UDFs (those with the I regard dynamic UDFs as one of the nicest features of xlwings. Unfortunately, as long dynamic UDFs cannot be fully relied upon to always correctly recalculate results automatically it is prohibiting me from sharing my xlwings-workbooks with dynamic UDF's with my coworkers. I have used them myself for some time, refreshing manually with F2, Enter. The problem Towards a solution While searching GitHub I noticed PR #872 by @Colin-b who is also trying to solve this same problem. His approach has some resemblance to mine, with two differences. A minor one is that his PR introduces a second queue whereas I requeue a task again at the front of the original queue. A more important one is that it does not have the periodic polling which I found to be necessary as one cannot be sure that there will always be another task arriving to trigger the retrying of an earlier one. I have never used git before, but I managed to create a personal fork of xlwings at https://github.com/rhkleijn/xlwings/tree/robust-task-retry) and put (a cleaner version) of my approach in there. Feel free to try it and if you find this useful, I can submit it as a PR. |
I introduced the 10 times retry mechanism when encountering this issue for
the first time. And with a whole lot more udf being called 'at once' by
Excel, I updated it to this new PR you are talking about. It is implemented
in a forked version and used since months already so it covers my use case.
I am more than willing to consider removing it if you have a nicer solution
solving another problem then, do you know why your Excel is returning busy
if it is not because he is still calling udfs ?
…On Sat, May 26, 2018, 22:08 rhkleijn ***@***.***> wrote:
Count me in as well. I have also encountered this problem that dynamic
UDFs (those with the @xw.ret(expand=...) decorator) do not consistently
update the cells outside the cell containing the formula especially in
larger workbooks in which the output of a dynamic UDF is used in subsequent
calculations.
I regard dynamic UDFs as one of the nicest features of xlwings.
Unfortunately, as long dynamic UDFs cannot be fully relied upon to always
correctly recalculate results automatically it is prohibiting me from
sharing my xlwings-workbooks with dynamic UDF's with my coworkers. I have
used them myself for some time, refreshing manually with F2, Enter.
*The problem*
A couple of months ago I decided to dig into the source code of xlwings
and noticed that xlwings retries at most 10 times before it drops the task.
Retrying is needed when Excel temporarily doesn't allow writing because it
is busy with something else.
*Towards a solution*
I hacked the source code of my local xlwings installation to not limit the
number of retries while at the same not clogging the system. I implemented
this by retrying periodically (at least every 100 ms) or earlier when
another task arrived. For me this has made a lot of difference.
While searching GitHub I noticed PR #872
<#872> by @Colin-b
<https://github.com/Colin-b> who is also trying to solve this same
problem. His approach has some resemblance to mine, with two differences. A
minor one is that his PR introduces a second queue whereas I requeue a task
again at the front of the original queue. A more important one is that it
does not have the periodic polling which I found to be necessary as one
cannot be sure that there will always be another task arriving to trigger
the retrying of an earlier one.
I have never used git before, but I managed to create a personal fork of
xlwings at https://github.com/rhkleijn/xlwings/tree/robust-task-retry)
<https://github.com/rhkleijn/xlwings/tree/robust-task-retry> and put (a
cleaner version) of my approach in there
<rhkleijn@175d6da>
.
Feel free to try it and if you find this useful, I can submit it as a PR.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#880 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHPX_T1GqgT_Fze6AoXGEB1PvjZTTYMQks5t2bZVgaJpZM4UNko4>
.
|
Thanks for your reaction. I’ll share my solution as a PR. I expect it to work in all cases where your solution works plus some more. I suspect Excel is busy (by which I mean in this context that it returns RPC_E_SERVERCALL_RETRYLATER) not only from its regular recalculation activities (walking its dependency graph and evaluating formulas, including calliing UDFs), but that the delayed writes from dynamic UDFs cause all kinds of additional (blocking) activities. |
thank's a lot for your answers ! but i think that it is incredible haha now the first function that wouldn't be refreshed on excel is now well calculated and well refreshed but it seems that my others functions aren't refreshed ... |
I've tested different tyhings like replace all my formulas to have only UDFs but it doesn't work much more. interestingly, the first function to be called calcul well but doesn't seem to display the return result before excel call the next function .... so my second function take the wrong input to make all its calculus |
Louis-Alexis, this has been recognised as a bug, but it is only a problem when you use 'expand = table'. If you remove that line you can still enter the UDFs as array functions, and they will update when ever any input data changes, or you do a global recalculation. |
DougAJ4 okay, thank you very much ! |
Louis-Alexis, especially the combination of
The UDF itself being marked Can you retry with |
Okay ! i tried with volatile = False thank's for your support |
I've just found something really interesting. I've created a macro that calcul step by step the cells, columns, rows i want, in the good order (using selection.calculate) and i've put a button. it seems to work better but in order to have your sheet refreshed, you need in that way to click on the button and then move the mouse out in order to refresh the dynamics arrays ... haha that's really weird. EDIT : EDIT : |
I'm also having this same issue, and my function is pretty basic. No expanding table or anything like that. Just some date calculations.
|
Hi I have the same problem. I created a excel function UDF to do a tensorflow neural network. If I try to run several cells in one go (with different inputs), then after 3-4 cells it exists with "Automation Error" message. I tried using search and replace = by =, tried selection.calculate, SHIFT+F9, nothing helps. More than 3-4 cells and it stops. I am using windows 10, excel office profession plus 2016, Python 3.6.6 :: Anaconda custom (64-bit), xlwings version 0.11.8. |
fixed by #881 |
Hi everyone, I'm having an issue when returning an array to excel with a UDF.
when i launch a shift + F9 to recalculate all the sheet, one of my UDF function is well called and seems to return the good result ( i've set a message box before returning the array and it seems that the array is good), but the result is not display in the cells and so it is the prior result that stay in the cells. Refreshing problem maybe ?
So the other functions in the sheet are recalculated with the wrong datas.
So i have to calculate this function manually and alone cto see the good array in the cells.
Does someone have an idea of why ?
thank you very much. here is the mask of the function :
The text was updated successfully, but these errors were encountered: