Python win32com out of memory error

0

In order to operate a 3rd party device, I use python's win32com module to interact with the provided UI. This works as expected in general, but rarely (every 10k calls or so) the COM API throws the error -2147024888 (0x80070008) with the description not enough storage is available to process this command. This is very annoying, because it usually kills the device during the night and the running procedure needs to be repeated entirely.

The question now is, what actually is out of memory, because I am quite certainly not hitting any RAM limitations. Digging deeper into the problem, I found that I also cannot close and re-open the COM connection, since this results in error -2147024882 (0x8007000e) described as out of memory. However, this answer hints that actually no memory problem is involved. As another explaination, too many used handles are suggested here.

That idea would be supported by the observation, that I cannot fork threads anymore at this point. Calling start() on a threading.Thread I obtain

RuntimeError: can't start new thread

although only 4 threads are running according to threading.active_count(). At the same time, none of these problems are observed from a different process running python. Hence, I suspect that my process runs out of some ressource, but I don't know which. For the moment I see two options on how to proceed.

  • Option 1: Find out what ressource my process is running out of. However, I am not really an expert on debugging. What could I try to do, in order to understand better what is going on behind the scenes?

  • Option 2: Live with the problem and work around it. Error catching appears not to be sufficient in this case. As soon as the error occurs, there seems to be no way to get everything working again without killing the python process. Of course, this is not possible from within python.

    As a solution I thought about using the multiprocessing module and having all device-related calls running in a separate process. If something goes wrong, I kill the proces form my main programm and start it again with the possibility to continue at the point, where the error occured.

For both options I would be happy for suggestions or guidelines. Maybe there is also something entirely different, which I haven't thought about. Any help is appreciated.


Edit: Motivated by Ben's comment, I looked up some properties of the still running process, in which the errors occured. Here is a list of the data, which I consider as potentially useful:

  • 1.7G commit size with only 21M used and 500M peak memory (on Win7 x86)
  • 800k paging errors
  • 772 handles
  • 20 threads
python
winapi
com
win32com
asked on Stack Overflow Mar 11, 2016 by ranguwud • edited Jun 20, 2020 by Community

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0