[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Garbage collection



At 4:09 +1030 11/21/99, Henry Penninkilampi wrote:
>Assumptions:  When a user quits a MacPerl application, a 'quit' Apple
>Event is sent by the MacOS to that application.  The application is
>responsible for performing any garbage collection that is required.

When you quit a program by using its Quit command in the File menu, MacOS
does not get involved in the way you suggest.  The application may or may
not sent itself a Quit Apple event, depending upon its implementation.

The Finder and Process Manager conspire to send a Quit Apple event to a
program if it is running when Restart or Shutdown is selected from Finder's
special menu.

Later in the message thread, you indicated that code you wrote would not
create a file for you in the END block.

This vast program does (it's quite likely that your disk volume is not
named "Bainbridge"):

END {
    open TEST, ">Bainbridge:Desktop Folder:test.log" or die "Oops $!";
    print TEST "This is a test\n";
    close TEST;
    print "\a";
}

Your code and actions, however, differ from that simple case:

>Once again, I'm just trying to get something simple working, like this:
>
>---
>#!perl -w
>
>END
>{
>  open LOG, ">>LOG.TXT";
>  print LOG "END executed!\n";
>  close LOG;
>}
>
>print "Enter a command: ";
>$command = <STDIN>;
>print $command;
>---
>
>Run the script.  Instead of entering something at the prompt, select
>"Quit" from the the "File" menu.  The END subroutine does *NOT* get
>executed (or, at least, nothing is written to the log file), and the
>following is reported to STDERR:
>
># Callback called exit.
># END failed--cleanup aborted.
>
>Any more ideas?

Yes...you seem to have discovered something which MacPerl can't do.  At
least here, when I follow your instructions, I get a message about whether
or not I want to abort the current script and quit MacPerl.  If instead of
Quit you select "Stop script" from the File menu, the log file does get
written (and then you can Quit).  (Saving the script as a "runtime" or a
"droplet" doesn't help.)

Your script should probably disable the Quit command in the File menu (if
possible...I haven't tried, but the toolbox commands should manage it).
But that probably won't help with the user who selects Restart or Shutdown
in Finder while the script is running.  And it doesn't (tested) account for
someone running an AppleScript script like
   quit application "your script or MacPerl as the case may be"

       -----------
A future adjustment to what the MacPerl Quit command (or reception of a
Quit Apple event) does when a script is running may be indicated...perhaps
at a minimum the "Abort the current script" choice should run that script's
END block on the way out.

  --John



--
John W. Baxter, Port Ludow, WA, USA   jwbaxter@olympus.net
I'm trying to think, but nothing happens.

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org