start function in new process

wongjoekmeu at yahoo.com wongjoekmeu at yahoo.com
Sat Mar 6 04:45:46 EST 2010


On 5 mrt, 21:40, "Martin P. Hellwig" <martin.hell... at dcuktec.org>
wrote:
> On 03/05/10 20:09, wongjoek... at yahoo.com wrote:
>
>
>
> > On 5 mrt, 21:02, "Martin P. Hellwig"<martin.hell... at dcuktec.org>
> > wrote:
> >> On 03/05/10 19:45, wongjoek... at yahoo.com wrote:
>
> >>> On 5 mrt, 20:40, "Martin P. Hellwig"<martin.hell... at dcuktec.org>
> >>> wrote:
> >>>> On 03/05/10 19:21, wongjoek... at yahoo.com wrote:
> >>>> <cut os.fork problem>
> >>>> Any specific reason why threading.Thread or multiprocessing is not
> >>>> suitable to solve your problem?
>
> >>>> --
> >>>> mph
>
> >>> Because I got a memory leak in my function f(). It uses scipy, numpy,
> >>> pylab, and I am not planning to solve the memory leak because its too
> >>> complicated. So I thought of just calling the function then when it is
> >>> finished the process is gone and all memory is released. With
> >>> threading I don't think I would solve this problem. I am not sure
> >>> though.
>
> >> I would be surprised if you can't do the same with
> >> subprocess/multiprocessing, since you seem to know how to identify the
> >> memory leak it shouldn't be a problem scripting out a test to see if it
> >> works this way. I would be interested though in your findings.
>
> >> --
> >> mph
>
> > I can't use multiprocessing module since it comes only with python 2.6
> > and I am bound to python2.4. But subprocess does exist in python2.4,
> > but the question now is, how do I achieve that ? Any example ?
>
> Sure, for example if I want to check the openssl version (didn't specify
> I need to provide a useful example :-)
>
> I would normally do on the command line:
> [martin at aspire8930 /usr/home/martin/Desktop]$ /usr/bin/openssl version
> OpenSSL 0.9.8k 25 Mar 2009
>
> The python subprocess equivalent is:
> [martin at aspire8930 /usr/home/martin/Desktop]$ python
> Python 2.6.4 (r264:75706, Jan 31 2010, 20:52:16)
> [GCC 4.2.1 20070719  [FreeBSD]] on freebsd8
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> import subprocess as _sp
>  >>> ssl_version = _sp.Popen(['/usr/bin/openssl', 'version'],
> stdout=_sp.PIPE)
>  >>> print(ssl_version.stdout.readlines())
> ['OpenSSL 0.9.8k 25 Mar 2009\n']
>  >>> quit()
> [martin at aspire8930 /usr/home/martin/Desktop]$
>
> If you get any error in the Popen part, you probably did not use the
> full path or an illegal parameter.
>
> If you get a long wait in the readlines part, this usually means that
> there is either nothing written to stdout or something is still being
> written (I am not sure about this part though, it has been a while).
>
> hth
> --
> mph

Yes, I saw this example also before. HOwever what I want is to call an
internal function which gets a reference of another internal function
as input and not calling an external program. Do you have any example
on that with subprocess module ?
Thanks.



More information about the Python-list mailing list