PyXLL The Python Excel Add-In
  • Product
    • Features
    • Get Started
    • Request Demo
    • Download
  • Pricing
  • Resources
    • Documentation
    • Blog
    • Videos
    • FAQ
    • Learn Python
    • Customer Portal
    • About Us
  • Support
    • Documentation
    • Videos
    • FAQ
    • Contact Us
  • Contact Us
Table of Contents
  • PyXLL Documentation
  • Introduction to PyXLL
  • User Guide
    • Installing PyXLL
    • Configuring PyXLL
    • Worksheet Functions
      • Introduction
      • Argument and Return Types
      • Cached Objects
      • Array Functions
      • NumPy Array Types
      • Pandas Types
      • Polars DataFrames
      • Asynchronous Functions
      • Function Documentation
      • Variable and Keyword Arguments
      • Recalculating On Open
      • Recalculating On Reload
      • Interrupting Functions
    • Macro Functions
    • Real Time Data
    • Cell Formatting
    • Charts and Plotting
    • Custom Task Panes
    • ActiveX Controls
    • Using Pandas in Excel
    • Customizing the Ribbon
    • Context Menu Functions
    • Working with Tables
    • Python as a VBA Replacement
    • Menu Functions
    • Reloading and Rebinding
    • Error Handling
    • Deploying your add-in
    • Workbook Metadata
  • Video Guides and Tutorials
  • API Reference
  • What’s new in PyXLL 5
  • Changelog
Close

Interrupting Functions¶

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.

« Recalculating On Reload
Macro Functions »
  • Home
  • Product
  • Features
  • Documentation
  • Download
  • Pricing
  • Support
  • Documentation
  • Videos
  • FAQ
  • Learn Python
  • Contact Us
  • About
  • About Us
  • Legal
  • Blog
© Copyright PyXLL Ltd