in reply to threads hang

A thread must reach the end of it's code block OR return, for it to end properly. I would suspect that
my $retval = `/usr/bin/snmpget -v1 -c <commstring> $ip sysDescr.0`;
is hanging, and stoping the flow of the code. Is there someway to set a timeout on it, or wrap it in an eval?

Alarms don't work well in threads, but you could try running a parallel thread to act as a timer, and run the snmpget command thru a piped-open or IPC::Open3 so you get a pid that can be killed when the timer times out.


I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: threads hang
by Ryszard (Priest) on Jan 17, 2008 at 13:55 UTC
    actually i guess snmpget has an implicit timeout as if i cant connect to a device, i get a timeout message on STDERR :-)
      Then run the backtick with `command 2>&1` and it shouldn't hang, as eventually it will get the stderr return.

      I'm not really a human, but I play one on earth. Cogito ergo sum a bum
        what you're describing (at least the way i interpret it) is a pause, not a hang.

        the issue i have is the threads hang, ie *never* finish, which AFAICT has nothing to do with error outputting.