Author Topic: run python function in the background  (Read 554 times)


  • Newbie
  • *
  • Posts: 5
  • Karma: 0
    • View Profile
run python function in the background
« on: October 21, 2015, 08:16:14 PM »
Hi, I am calling a python function, which performs a lengthy computation, in VBA using pyxll. I don't really need the return of this function anywhere else in excel or in VBA, as it just saves a csv file when the computation is done, however for the time it takes to finish the computation the sheet is hanging. Is there any way, through asynchronous functions or otherwise, to have the python function run in the background, while I continue to work on the spreadsheet? If you can post some very simple sample code it would be fantastic as ive never worked with asynchronous functions.
Here is what my Python and VBA code look like:
Code: [Select]
@xl_func("int x, int y")
def foo_to_csv(x,y):
     #writes something in a csv file

and the VBA
Code: [Select]
Sub call_foo_from_VBA()
     Application.Run("foo_to_csv", 0, 1)
End Sub


  • Administrator
  • Hero Member
  • *****
  • Posts: 661
  • Karma: 15
    • View Profile
Re: run python function in the background
« Reply #1 on: October 21, 2015, 08:23:24 PM »

you can start a background thread to perform the calculation.
See the documentation for the standard threading module here:

Best regards,