Function atexit and Ctrl+C

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Function atexit and Ctrl+C

phofman
Hi,

I am trying to run atexit in a script started in octave command of the
GUI environment. I stop the script with Ctrl+C, please is there a way to
run a function at such moment? Ctrl+C seems to skip the atexit feature.

Reason: my script opens a figure and I want to close the figure when the
script ends in GUI command.

Octave 4.2, linux

Thanks lot in advance.

Best regards,

Pavel.


Reply | Threaded
Open this post in threaded view
|

Re: Function atexit and Ctrl+C

mmuetzel
On 28 Jan 2019 20:46:29 +0100 Pavel Hofman wrote:
> I am trying to run atexit in a script started in octave command of the
> GUI environment. I stop the script with Ctrl+C, please is there a way to
> run a function at such moment? Ctrl+C seems to skip the atexit feature.

"atexit" is used to register a function that executes when Octave closes (not at the end of the script).

> Reason: my script opens a figure and I want to close the figure when the
> script ends in GUI command.

I am not sure whether I understand your goal. But you could probably enclose your script inside an unwind-protect block like:
unwind_protect
  hf = figure;
  while 1
  endwhile
unwind_protect_cleanup
  close (hf);
end_unwind_protect

Markus


Reply | Threaded
Open this post in threaded view
|

Re: Function atexit and Ctrl+C

phofman
Hi Markus
Dne 03. 02. 19 v 17:50 "Markus M├╝tzel" napsal(a):
>
> I am not sure whether I understand your goal. But you could probably enclose your script inside an unwind-protect block like:
> unwind_protect
>    hf = figure;
>    while 1
>    endwhile
> unwind_protect_cleanup
>    close (hf);
> end_unwind_protect

Your are the man! Thanks a lot, exactly what I was looking for. Ctrl+C
does not skip the unwind block, working like a charm.

Thanks a lot,

Pavel.