Re: run function in separate process

2007-04-11 Thread malkarouri
After playing a little with Alex's function, I got to: import os, cPickle def run_in_separate_process_2(f, *args, **kwds): pread, pwrite = os.pipe() pid = os.fork() if pid > 0: os.close(pwrite) with os.fdopen(pread, 'rb') as f: status, result = cPickle.load(

Re: run function in separate process

2007-04-11 Thread malkarouri
After playing with Alex's implementation, and adding some support for exceptions, this is what I came up with. I hope I am not getting too clever for my needs: import os, cPickle def run_in_separate_process_2(f, *args, **kwds): pread, pwrite = os.pipe() pid = os.fork() if pid > 0:

Re: run function in separate process

2007-04-11 Thread malkarouri
On Apr 11, 4:36 pm, [EMAIL PROTECTED] wrote: [...] > .. And I avoided pickle at the time > because I had a structure that was unpicklable (grown by me using a > mixture of python, C, ctypes and pyrex at the time). The structure is > improved now, and I will go for the more standard approach.. Sorr

Re: run function in separate process

2007-04-11 Thread malkarouri
On Apr 11, 3:58 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: [...] > That's my favorite way to ensure that all resources get reclaimed: let > the operating system do the job. Thanks a lot, Alex, for confirming the basic idea. I will be playing with your function later today, and will give more fee

Re: run function in separate process

2007-04-11 Thread malkarouri
Thanks Mike for you answer. I will use the occasion to add some comments on the links and on my approach. I am programming in Python 2.5, mainly to avoid the bug that memory arenas were never freed before. The program is working on both Mac OS X (intel) and Linux, so I prefer portable approaches.

Re: run function in separate process

2007-04-11 Thread Alex Martelli
<[EMAIL PROTECTED]> wrote: ... > somebody points me to a web page/reference that says how to call a > function then reclaim the whole memory back in python. > > Meanwhile, the best that I could do is fork a process, compute the > results, and return them back to the parent process. This I That

Re: run function in separate process

2007-04-11 Thread kyosohma
On Apr 11, 9:23 am, [EMAIL PROTECTED] wrote: > Hi everyone, > > I have written a function that runs functions in separate processes. I > hope you can help me improving it, and I would like to submit it to > the Python cookbook if its quality is good enough. > > I was writing a numerical program (us