Start application & continue after app exits

Ivan Shevanski darkpaladin79 at hotmail.com
Thu Jun 9 18:25:30 CEST 2005


>From: Paul McNett <p at ulmcnett.com>
>To: python-list at python.org
>Subject: Re: Start application & continue after app exits
>Date: Thu, 09 Jun 2005 09:07:47 -0700
>
>Guy Lateur wrote:
> > I was wondering if it would be possible to launch an application, block
> > until the app exits, and do some cleanup afterwards.
>
> > Maybe an example will be clearer: I would like to make a temperary 
>(text)
> > file, open it with MS Word for the user to edit/layout/print, and then
> > delete the temp file after the user shuts down Word. Is this feasible?
>
>Something like:
>
>import os
>import tempfile
>
>testString = "Life is but a dream."
>fileName = tempfile.mktemp()
>print fileName
>open(fileName, "w").write(testString)
>os.system("gedit %s" % fileName)
>os.remove(fileName)
>
>---
>Note that I'm on Linux, and instead of launching Word I'm launching an
>editor named "gedit". You could likely change that call to winword.exe,
>but I haven't tested it on Windows.
>
>Also note that this method of creating tempfiles is technically unsafe,
>as it is theoretically possible that another process would create a file
>of the same name in the same directory and then try to use it, resulting
>in a race condition between the two processes. This is practically
>unlikely, however, and I'm a pragmatist.
>
>
>--
>Paul McNett
>http://paulmcnett.com

--
Perhaps try the sys.exitfunc or atexit modules:

exitfunc
This value is not actually defined by the module, but can be set by the user 
(or by a program) to specify a clean-up action at program exit. When set, it 
should be a parameterless function. This function will be called when the 
interpreter exits. Only one function may be installed in this way; to allow 
multiple functions which will be called at termination, use the atexit 
module. Note: The exit function is not called when the program is killed by 
a signal, when a Python fatal internal error is detected, or when os._exit() 
is called.
Deprecated since release 2.4. Use atexit instead.

heres the link   <http://python.org/doc/2.4.1/lib/module-sys.html>

Hope it helps,
-Ivan

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/




More information about the Python-list mailing list