Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Stopping hanging commands (evals) within debugger

by LanX (Saint)
on Dec 16, 2012 at 21:42 UTC ( [id://1009096]=perlquestion: print w/replies, xml ) Need Help??

LanX has asked for the wisdom of the Perl Monks concerning the following question:

hi

I'm more and more using my modified debugger as a shell replacement for bash.

But one thing bugs me, long running commands like loops can't be stopped by Ctrl-c.

The only way I know to stop a hanging command is to Ctrl-z and then killing the whole debugger-process (including the unsaved history)

Any suggestions how I can avoid this?

Maybe I can patch the eval to react on signals?

Cheers Rolf

  • Comment on Stopping hanging commands (evals) within debugger

Replies are listed 'Best First'.
Re: Stopping hanging commands (evals) within debugger
by BrowserUk (Patriarch) on Dec 17, 2012 at 00:07 UTC

    Just wrap your string eval in a block eval in which you set a %SIG{ INT } = sub{ die; }; ie:

    eval { local $SIG{ INT } = sub{die}; eval $_code };

    If you also want to be able to break out of long-running opcodes, you'd have to look at setting local $ENV{ PERL_SIGNALS } = 'unsafe';.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.

    RIP Neil Armstrong

      Excellent, testscript works fine! =)

      $|=1; $_code=' sleep 1, print for (1..100)'; eval { local $SIG{ INT } = sub{die;}; eval $_code }; print "after interrupt"; eval $_code; # again w/o wrapper

      I'll post again when I got it integrated within the debugger!

      Cheers Rolf

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-24 01:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found