Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Reliable exit control

44 views
Skip to first unread message

Darren New

unread,
Sep 6, 2006, 8:29:46 PM9/6/06
to
Is there any way in pure Tcl to reliably do something when the program
is about to be exited? According to Tcl_Exit man page, one can register
exit handlers. There doesn't seem to be a Tcl equivalent.

I also have this code, running in 8.5a1:


proc newexit {} {
outline "DIE" [clock seconds]
_exit
}
rename exit _exit
rename newexit exit
wm protocol . WM_DELETE_WINDOW exit

and that doesn't seem to invoke outline when the process exits, unless I
exit by explicitly clicking the close box. Logging out while it's
running, or cleanly rebooting, doesn't seem to invoke the exit proc.

What I really want is a program running that records when the user
logged out. This doesn't seem to be working.

--
Darren New / San Diego, CA, USA (PST)
Just because you find out you are
telepathic, don't let it go to your head.

Jeff Hobbs

unread,
Sep 7, 2006, 12:21:06 AM9/7/06
to Darren New
Darren New wrote:
> Is there any way in pure Tcl to reliably do something when the program
> is about to be exited? According to Tcl_Exit man page, one can register
> exit handlers. There doesn't seem to be a Tcl equivalent.
>
> I also have this code, running in 8.5a1:
>
>
> proc newexit {} {
> outline "DIE" [clock seconds]
> _exit
> }
> rename exit _exit
> rename newexit exit
> wm protocol . WM_DELETE_WINDOW exit
>
> and that doesn't seem to invoke outline when the process exits, unless I
> exit by explicitly clicking the close box. Logging out while it's
> running, or cleanly rebooting, doesn't seem to invoke the exit proc.

If you are using at least 8.4.13, add also:

wm protocol . WM_SAVE_YOURSELF exit

--

Jeff Hobbs, The Tcl Guy, http://www.activestate.com/

Darren New

unread,
Sep 7, 2006, 12:53:18 AM9/7/06
to
Jeff Hobbs wrote:
> If you are using at least 8.4.13, add also:
> wm protocol . WM_SAVE_YOURSELF exit

8.5a1, and nope. BTW, this is Windows.

suchenwi

unread,
Sep 7, 2006, 7:39:22 AM9/7/06
to

Darren New schrieb:

> Jeff Hobbs wrote:
> > If you are using at least 8.4.13, add also:
> > wm protocol . WM_SAVE_YOURSELF exit
>
> 8.5a1, and nope. BTW, this is Windows.

Uh.. that's a few years old... :) If you use alpha, best take the
latest (8.5a4)

Glenn Jackman

unread,
Sep 7, 2006, 10:42:57 AM9/7/06
to
At 2006-09-06 08:29PM, "Darren New" wrote:
> proc newexit {} {
> outline "DIE" [clock seconds]
> _exit
> }
> rename exit _exit
> rename newexit exit
> wm protocol . WM_DELETE_WINDOW exit

I don't get why you're renaming. Why don't you just
wm protocol . WM_DELETE_WINDOW newexit

Also, is newexit in a namespace. I assume the WM_DELETE_WINDOW handler
would be looking in the global namespace.

--
Glenn Jackman
Ulterior Designer

Darren New

unread,
Sep 7, 2006, 1:20:55 PM9/7/06
to
Glenn Jackman wrote:
> I don't get why you're renaming. Why don't you just
> wm protocol . WM_DELETE_WINDOW newexit

I was under the impression (from earlier conversations here a while
back) that [exit] is called whenever the interpreter exits, even if it's
not from closing the window via a WM_DELETE_WINDOW. E.g., by logging out.

> Also, is newexit in a namespace. I assume the WM_DELETE_WINDOW handler
> would be looking in the global namespace.

Nope. It's a 15-line program overall. Too simple to worry about such. It
works OK if I actually click the close box. I'm looking to catch exits
caused by closing the window without clicking the close box.

Darren New

unread,
Sep 7, 2006, 1:25:50 PM9/7/06
to
suchenwi wrote:
> Uh.. that's a few years old... :) If you use alpha, best take the
> latest (8.5a4)

I know, thanks. I use Tcl idly-like now, rather than as a production
language, so being old isn't a problem. I'm not pushing the cutting
edge. The only reason I upgraded before was to try to fix the problem of
the windows not refreshing when the resolution/depth changed.

Joe English

unread,
Sep 8, 2006, 4:25:46 PM9/8/06
to
Jeff Hobbs wrote:
>Darren New wrote:
>> Is there any way in pure Tcl to reliably do something when the program
>> is about to be exited? [...]
> [...]

>If you are using at least 8.4.13, add also:
>
>wm protocol . WM_SAVE_YOURSELF exit

**** DANGER DANGER DANGER ****

Do *not* do this if the program will ever be run under X11.

WM_SAVE_YOURSELF is part of the older session manager protocol;
SMs can send WM_SAVE_YOURSELF at any time, not just when
the session is about to end.

Also, if you register a WM_SAVE_YOURSELF handler make sure
that it calls [wm command $win ...]; this tells the SM that
the app has finished processing the message. If you don't
do this, it can prevent users from logging out while your
application is active.


--Joe English

0 new messages