0

I have a code which basically manipulates xlsm file, presses a macro button, and then force closing it (using psutil)

the process is: open xlsm file (MyExcel.xslm)==> write data ==> press macro button, save==> force close (with psutil).

and the process repeats 'x' times (lets say 20000 times)

this is the force close:

for proc in psutil.process_iter():
        if proc.name() == "EXCEL.EXE":
             proc.kill()

and in a totaly random run, python stop running with the following error:

  File "C:\Program Files\Python36\lib\site-packages\xlwings    \_xlwindows.py", line 296, in __init__
    self._xl = COMRetryObjectWrapper(DispatchEx('Excel.Application'))
  File "C:\Program Files\Python36\lib\site-packages\win32com\client\__init__.py", line 113, in DispatchEx
   dispatch = pythoncom.CoCreateInstanceEx(clsid, None, clsctx,   serverInfo, (pythoncom.IID_IDispatch,))[0]
 pywintypes.com_error: (-2146959355, 'Server execution failed', None, None)

I am using python 3.6.6, xlwings =0.15.1

tried to add delays (time.sleep(1)), to add some time between runnings

it always failing in this line (last line):

class RoutingManipulator():

def __init__(self):

    self.__number_of_cells = 48
    self.new_file = os.path.join(folder, file)self.new_file= Myfile.xlsm

    self.workBook = xw.Book(self.new_file) # FAILS HERE!!

in this example, it only failed in run number =612.

sometimes it fails in 500.. and so on

Danny Kaminski
  • 191
  • 2
  • 15

1 Answers1

0

As the comment above showed, I have implemented an internal kill,

self.workBook.app.kill()

it seems that it has solved the issue.

Danny Kaminski
  • 191
  • 2
  • 15