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(
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:
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
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
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.
<[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
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