Call object cleanup method when IDL exits [message #85620] |
Thu, 22 August 2013 06:04  |
dg86
Messages: 118 Registered: September 2012
|
Senior Member |
|
|
Dear Folks,
I want to ensure that my object's cleanup method is called when IDL exits.
What's the right way to do this?
The issue is that my object spawns a background process that it subsequently
kills when the object is cleaned up. It appears that IDL does not automatically
call objects' cleanup methods when it shuts down normally.
Consequently, the background process can be left running.
This isn't a problem for well-written programs that explicitly call obj_destroy.
It arises all the time during interactive sessions, however.
Is there a switch that tells IDL to be extra fastidious about cleaning up objects?
Perhaps an equivalent to IDL_STARTUP that works on shutdown? Or is there some
other technique to ensure that every object on the heap is cleaned up before
IDL shuts down?
Many thanks,
David
|
|
|
Re: Call object cleanup method when IDL exits [message #85623 is a reply to message #85620] |
Thu, 22 August 2013 07:31   |
Moritz Fischer
Messages: 32 Registered: June 2013
|
Member |
|
|
Hi David,
sorry, I didn't mean to pm you.
However, I just figured out you can do this:
PRO my_exit
help, LEVEL=-1, OUTPUT=o
funny_array = strsplit( strjoin( o, ' '),' ', /EXTRACT)
foreach var, funny_array do $
tmp = temporary( scope_varfetch(var, LEVEL=-1, /ENTER) )
tmp=42
exit
END
Neverthe less: Let me know if you find something more elegant!
cheers
Am 22.08.2013 15:04, schrieb David Grier:
> Dear Folks,
>
> I want to ensure that my object's cleanup method is called when IDL exits.
> What's the right way to do this?
>
> The issue is that my object spawns a background process that it subsequently
> kills when the object is cleaned up. It appears that IDL does not automatically
> call objects' cleanup methods when it shuts down normally.
> Consequently, the background process can be left running.
>
> This isn't a problem for well-written programs that explicitly call obj_destroy.
> It arises all the time during interactive sessions, however.
>
> Is there a switch that tells IDL to be extra fastidious about cleaning up objects?
> Perhaps an equivalent to IDL_STARTUP that works on shutdown? Or is there some
> other technique to ensure that every object on the heap is cleaned up before
> IDL shuts down?
>
> Many thanks,
>
> David
>
|
|
|
|
Re: Call object cleanup method when IDL exits [message #85629 is a reply to message #85623] |
Thu, 22 August 2013 10:29   |
dg86
Messages: 118 Registered: September 2012
|
Senior Member |
|
|
Hi Moritz,
Thanks for this very helpful response. The only tweak I've added is to test
the strings returned by HELP to make sure that they're valid variable names.
My next step may be to emulate the IDL_STARTUP mechanism by testing
for an IDL_SHUTDOWN environment variable and executing any commands
in the named file before calling exit.
pro my_exit
help, level=-99, output=o
variables = strsplit(strjoin(o,' '),' ',/extract)
foreach var, variables do begin
if idl_validname(var) then begin
tmp = temporary(scope_varfetch(var, level=-1, /enter))
tmp = 42 ; the answer to the question
endif
endforeach
exit
end
All the best,
David
On Thursday, August 22, 2013 10:31:59 AM UTC-4, Moritz Fischer wrote:
> Hi David,
>
>
>
> sorry, I didn't mean to pm you.
>
> However, I just figured out you can do this:
>
>
>
> PRO my_exit
>
> help, LEVEL=-1, OUTPUT=o
>
> funny_array = strsplit( strjoin( o, ' '),' ', /EXTRACT)
>
> foreach var, funny_array do $
>
> tmp = temporary( scope_varfetch(var, LEVEL=-1, /ENTER) )
>
> tmp=42
>
> exit
>
> END
>
>
>
> Neverthe less: Let me know if you find something more elegant!
>
>
>
> cheers
>
>
>
> Am 22.08.2013 15:04, schrieb David Grier:
>
>> Dear Folks,
>
>>
>
>> I want to ensure that my object's cleanup method is called when IDL exits.
>
>> What's the right way to do this?
>
>>
>
>> The issue is that my object spawns a background process that it subsequently
>
>> kills when the object is cleaned up. It appears that IDL does not automatically
>
>> call objects' cleanup methods when it shuts down normally.
>
>> Consequently, the background process can be left running.
>
>>
>
>> This isn't a problem for well-written programs that explicitly call obj_destroy.
>
>> It arises all the time during interactive sessions, however.
>
>>
>
>> Is there a switch that tells IDL to be extra fastidious about cleaning up objects?
>
>> Perhaps an equivalent to IDL_STARTUP that works on shutdown? Or is there some
>
>> other technique to ensure that every object on the heap is cleaned up before
>
>> IDL shuts down?
>
>>
>
>> Many thanks,
>
>>
>
>> David
>
>>
|
|
|
Re: Call object cleanup method when IDL exits [message #85630 is a reply to message #85620] |
Thu, 22 August 2013 10:36  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 8/22/13 7:04 AM, David Grier wrote:
> Is there a switch that tells IDL to be extra fastidious about cleaning up objects?
> Perhaps an equivalent to IDL_STARTUP that works on shutdown? Or is there some
> other technique to ensure that every object on the heap is cleaned up before
> IDL shuts down?
The only hook into when IDL exits that I know of is the routine
registered with IDL_ExitRegister in a DLM.
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|