Long running functions can cause Excel to become unresponsive and sometimes it’s desirable to allow the user to interrupt functions before they are complete.
Excel allows the user to signal they want to interrupt any currently running functions by pressing the Esc key.
If a Python function has been registered with allow_abort=True (see xl_func
) PyXLL will raise a
KeyboardInterrupt
exception if the user presses Esc during execution of the function.
This will usually cause the function to exit, but if the
KeyboardInterrupt
exception is caught then notrmal Python
exception handling takes place. Also, as it is a Python exception that’s
raised, if the Python function is calling out to something else (e.g. a C
extension library) the exception may not be registered until control is
returned to Python.
Enabling allow_abort registers a Python trace function for the duration of the call to the function. This can have a negative impact on performance and so it may not be suitable for all functions. The Python interpreter calls the trace function very frequently, and PyXLL checks Excel’s abort status during this trace function. To reduce the performance overhead of calling this trace function, PyXLL throttles how often it checks Excel’s abort status and this throttling can be fine-tuned with the config settings abort_throttle_time and abort_throttle_count. See PyXLL Settings for more details.
The allow_abort feature can be enabled for all functions by setting it in the configuration. This feature should be used with caution because of the performance implications outlined above.
[PYXLL]
;
; Make all Excel UDFs inherently interruptable
;
allow_abort = 1
It is not enabled by default because of the performance impact, and also because it can interfere with the operation of some remote debugging tools that use the same Python trace mechanism.