Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Perl/Tk and exit(0) [Tk::exit]

by kcott (Archbishop)
on Apr 03, 2020 at 07:05 UTC ( [id://11114975]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl/Tk and exit(0)
in thread Perl/Tk and exit(0)

G'day 1nickt,

The link you posted labeled "exit" is to a Google search (http://www.google.com/search?q=exit%20site%3Aperldoc.perl.org). The first item returned from that search is to perldoc (https://perldoc.perl.org/functions/exit.html). I couldn't see anything else pertinent, so I'm wondering why the intermediary Google step. Anyway, the point is somewhat moot as that's the wrong "exit".

"I am not a Tk programmer ..."

In my experience, even amongst Tk programmers, it's a little known fact that Tk exports, by default, its own exit: Tk::exit.

Knowing that doesn't help the OP but I thought it was worth mentioning.

— Ken

Replies are listed 'Best First'.
Re^3: Perl/Tk and exit(0) [Tk::exit]
by 1nickt (Canon) on Apr 03, 2020 at 07:43 UTC

    Thanks Ken, I'll update the link. Not sure how that happened.

    Update: I fixed the links by changing from [perldoc:// to [doc://. I wonder if the behaviour of the former syntax is new, broken, or something I just imagined was different. The links as I originally posted definitely went to a Goog search. Maybe a topic for PM Discussion...

    The way forward always starts with a minimal test.
      "I wonder if the behaviour of the former syntax is new, broken, or something I just imagined was different."

      Unfortunately, I suspect it may be the latter.

      I rarely, if ever, use those shortcuts; however, checking in "What shortcuts can I use for linking to other information?", I see (my emphasis added):

      The Perl documentation:

      • Search the Perl docs: [perldoc://search terms]
      • Link directly to a the doc of a function or variable: [doc://name] ...

      There was a change to [doc://name] back in February: "NEW [doc://perldoc#deeplink] works now with all perldocs". I don't recall any recent changes to [perldoc://search terms].

      "Maybe a topic for PM Discussion..."

      Or maybe not. :-)

      Unless you wish to request a typo fix: s/to a the doc/to the doc/

      — Ken

        [perldoc://search term] links to a Google search for the term in perldoc. It doesn't have another choice, in fact, as the current version of perldoc.perl.org (unlike the perldoc.pl) doesn't have a working search.

        BTW, note the "official" documentation still shows 5.30.0, while the "open" documentation site correctly shows the latest 5.30.2.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^3: Perl/Tk and exit(0) [Tk::exit]
by jcb (Parson) on Apr 03, 2020 at 23:54 UTC

    As I understand, the two exit procedures only matter if you fork. Calling Tk's exit from a forked child causes the parent to also exit, while calling CORE::exit causes only that forked child to exit.

      G'day jcb,

      I'm unsure whether you posted this to corroborate what I said or correct something you believed I had wrong in some way. So, purely by way of clarification:

      • I was pointing out that the exit in a Tk script was the one described in https://metacpan.org/pod/distribution/Tk/pod/exit.pod and not the one described in https://perldoc.perl.org/functions/exit.html.
      • I was not, in any way, suggesting that changing from Tk::exit to CORE::exit would be beneficial for the OP. In fact, I wrote: "Knowing that doesn't help the OP ...".
      • What you wrote ("As I understand, the two exit procedures ...") pretty much paraphrases what's in the Tk::exit documentation; i.e. "Using exit from a forked process will terminate both the child process and the parent process. As Tk::exit is imported by default one should use CORE::exit in the forked process instead.".
      • The reason to generally prefer Tk::exit over CORE::exit is given in the preceding paragraph: "If calling exit from code invoked via a Tk callback then this Tk version of exit cleans up more reliably than using the perl exit.".

      If there was any miscommunication or misunderstanding, I hope that clears it up.

      — Ken

        It was intended to corroborate and to point out a difference that helps to explain why Tk replaces exit. My understanding of the two is from the documentation and my experience, which does not include Tk on Windows, so the difference I know about is that Tk::exit reliably destroys all of the MainWindows, while CORE::exit allows a forked worker (such as performing an LWP request without blocking the GUI) to safely exit after reporting its results back. On X11, calling Tk::exit from a forked child also causes the parent to exit.

      As I understand, the two exit procedures only matter if you fork.

      This is on windows, clean exit

      perl -e"use Tk; $mw=tkinit; $mw->Button(-command=>sub{ Tk::exit })->pa +ck; MainLoop; "

      Dirty exit

      perl -e"use Tk; $mw=tkinit; $mw->Button(-command=>sub{ CORE::exit })-> +pack; MainLoop; " perl.exe has encountered a problem and needs to close. Faulting application perl.exe, version 5.20.3.3, faulting module tk.xs +.dll, version 8.4.2.5, fault address 0x00044b1e.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11114975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-19 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found