Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by jcb (Parson)
on Apr 03, 2020 at 23:54 UTC ( [id://11115020]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl/Tk and exit(0) [Tk::exit]
in thread Perl/Tk and exit(0)

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.

Replies are listed 'Best First'.
Re^4: Perl/Tk and exit(0) [Tk::exit]
by kcott (Archbishop) on Apr 04, 2020 at 06:59 UTC

    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.

        ++ Thanks for the reply. Looks like we're all good. :-)

        — Ken

Re^4: Perl/Tk and exit(0) [Tk::exit]
by Anonymous Monk on Apr 04, 2020 at 04:41 UTC

    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://11115020]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found