Search code examples
pythonexcelxlwings

Does it make sense to always use asynchronous UDFs in xlwings for updating cells?


For xlwings UDFs that return a result that will be written to an Excel cell, does it make sense to always make the UDF asynchronous so that Excel does not freeze while processing the UDF?

Are there situations when not using asynchronous UDFs is better?

https://docs.xlwings.org/en/stable/udfs.html#asynchronous-udfs

I am using Excel 2016 and Windows 10


Solution

  • I think the real question is when to use asynchronous UDFs. The answer to that question is the same whether or not we are in the context of xlwings. I will quote MSFT:

    Some user-defined functions must wait for external resources. While they wait, the Excel calculation thread is blocked. User-defined functions can run asynchronously. This frees the calculation thread to run other calculations while the user-defined function waits.

    Extensive usage of asynchronous function in Excel, will be inefficient but I also suspect that it might lead to errors and incorrect application state. This is my opinion based on my experience but not official confirmed so I am looking forward to having expert opinion.