Recommended Answers

All 5 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.