Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^2: Exiting a script with an 'infinitely looping' thread

by markseger (Beadle)
on Nov 24, 2008 at 15:00 UTC ( #725608=note: print w/replies, xml ) Need Help??

in reply to Re: Exiting a script with an 'infinitely looping' thread
in thread Exiting a script with an 'infinitely looping' thread

Ahhh... I do trap the ^C in my real script but had been lazy in my test script. As soon as I put the ^C in my test script it too complained!

re detach thread - not sure how to do this but it sounds promising.

re share flag - yes, I did realize that doing this I'd need to periodically wake up and check the flag, the only real negative here is that it would delay the time it takes for my script to shut down to as much as the 'wake up ' time, something I'd prefer to avoid.


  • Comment on Re^2: Exiting a script with an 'infinitely looping' thread

Replies are listed 'Best First'.
Re^3: Exiting a script with an 'infinitely looping' thread
by BrowserUk (Pope) on Nov 24, 2008 at 15:07 UTC
    e detach thread - not sure how to do this but it sounds promising.

    See the pod for threads, but essentially where you currently do:

    my $immortal = threads->create( ...);


    threads->create( ...)->detach;

    is pretty much all there is to it. As the pod says:


    Makes the thread unjoinable, and causes any eventual return value to be discarded. When the program exits, any detached threads that are still running are silently terminated.

    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.
      Time for some code and here's what I'm doing. I still get the message. Gotta be some thing silly (I hope)
      #!/usr/bin/perl -w
      use threads;
      my $thread=threads->create('test')->detach();
      while(1) { sleep 100; }
      sub test { sleep 100; }
      sub sigInt { exit; }


Re^3: Exiting a script with an 'infinitely looping' thread
by ikegami (Pope) on Nov 24, 2008 at 16:12 UTC

    A quick note: Detaching the thread doesn't cause it to exit cleanly, just silently.

    #!/usr/bin/perl use threads; DESTROY { print "Destroyed\n" } sub test { my $x = bless({}); sleep() while 1; } $SIG{INT} = sub { exit }; my $thread = threads->create('test')->detach(); print("Press Ctrl-C to exit\n"); sleep();

    If the thread exited cleanly, the above prints Destroyed. It doesn't.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://725608]
[stevieb]: I really dislike how perlbrew doesn't list your version of perl if a newer minor version bump has happened. eg: I use 5.24.1, but 5.24.2 is available, hiding my 5.24.1. I may look at this, as I made it display correctly in berrybrew in cases like this
[stevieb]: choroba just gleaned your post about Module::Starter. I use it too, pretty much for every dist I write
[LanX]: I remeber M::S (it was dialog driven?) to be buggy
[stevieb]: As far as Dist::Zilla goes, I don't like installing that other than on systems my test platorm runs on. I find it too heavy. I prefer being able to glean a Makefile.PL
[LanX]: what's frustrating me is that a distribution has lots of dupplicated info

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2017-08-18 20:50 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (310 votes). Check out past polls.