Looks like all of those packages use Microsoft's COM and are then not under the jurisdiction of the ever so efficient Python memory manager. In other words, you are running an external program from Python.

So is there any way to free the resources / library used in the script ? even though it is an external library, imported into the script there will be a way to dispose once it has been used. Any ideas ?

Thanks

A solution is not to import your library xlwt but to start a child process which will import the library. You can then communicate with the child process through pipes, or using a module like pyro. When you are done with the xlwt, you terminate the child process and the memory is freed. I used this solution in the past for other reasons than memory, and it works well.

I have never tried creating as child process. Could u please help me in creating a child proces? Maybe a code snippet would do.

Thanks

Creating a child process is just starting another program from your python program. This is done with the subprocess module. This blog page http://blog.doughellmann.com/2007/07/pymotw-subprocess.html shows good examples. The main problem when you create a subprocess is: do you have to communicate with the subprocess, wich means do you have to send data to the subprocess from your program, and do you have to receive data from the subprocess ? Depending on the answer, the structure of your code may vary a lot.

This article has been dead for over six months. Start a new discussion instead.