in reply to Re: How to skip END blocks with threads?
in thread How to skip END blocks with threads?

Thanks, that works great. Unfortunately, I cannot affect the way the END block(s) are written.

I'm trying to have my module IPC::Exe avoid doing END blocks once exec fails in a child, so it doesn't act in a surprising way. From the looks of it, I may just abandon the idea (in favor of consistency) because I can't tell when threads are used.

exit and die seem to do the right thing when called inside a thread or a different process, but they also do END.
  • Comment on Re^2: How to skip END blocks with threads?

Replies are listed 'Best First'.
Re^3: How to skip END blocks with threads?
by BrowserUk (Patriarch) on May 05, 2009 at 02:42 UTC
    Unfortunately, I cannot affect the way the END block(s) are written.

    Then add an END block in your code, prior to useing the modules (any modules), whos end blocks you wish to disable, and call thread->exit() within that END block. Eg.

    #! perl ... # main.script my $originalPid = $$; END{ return if $$ == $originalPid; require threads; threads->exit; } use Foo; use Bar; ...
    • By putting your END block ahead of any modules you use, you ensure that your END block is called first.
    • If the curent pid == the pid when the code first ran, you are the parent, so quit early and allow the parent to run any END end blocks set up by the modules it uses.
    • Otherwise, you are a child, so call threads->exit before any other END blocks are called.

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Actually END blocks goes in LIFO order, which works out even better :) Let me experiment with your idea. Thanks again!
Re^3: How to skip END blocks with threads?
by Anonymous Monk on May 05, 2009 at 02:32 UTC
    When modules are loaded (like threads), they leave an entry %INC (besides creating an entry in %::)