Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Handle Signal and Wrap Up

by aukjan (Friar)
on Aug 19, 2005 at 13:53 UTC ( [id://485131]=note: print w/replies, xml ) Need Help??


in reply to Handle Signal and Wrap Up

It all depends on what you mean by finishing off the particular element. Do you mean that you are processing an element and now the program is interrupted, but you still want to continue with the same process?? This could be very dangerous, and should only be attemted if you know exactly where your program was when it was intterrupted. This means that you will have to keep track of every step in the processing of that element.

Please explain more clearly what your intentions are. And how you process your elements.

Go Fish!

Replies are listed 'Best First'.
Re^2: Handle Signal and Wrap Up
by dsb (Chaplain) on Aug 19, 2005 at 14:27 UTC
    Sorry for being vague. What I mean is that if the program is in the middle of processing the 3rd element in the stack and it receives an interrupt signal, I'd like it to finish the 3rd element and ONLY the third element before it exits. I don't want it to continue processing past that point.

    The processing is such that the element is shift()ed off the stack (duh), then sent to a function that will print to a log file, and send the element to a package for processing via DBI and DBD::ODBC (Access DB...meh!).

    Originally I was using threads, because I thought I might be able to process multiple stack elements simultaneously, but then the DBI docs said that wasn't a good idea.

    If the DBI and drivers are loaded and handles created before the thread is created then it will get a cloned copy of the DBI, the drivers and the handles.

    However, the internal pointer data within the handles will refer to the DBI and drivers in the original interpreter. Using those handles in the new interpreter thread is not safe, so the DBI detects this and croaks on any method call using handles that don't belong to the current thread (except for DESTROY).

    I'm about to stop using threads, though I haven't yet because I wasn't sure if I couldn't use them somehow to monitor results from the processing. But then, since I'm only able to go one at a time anyway, I might as well just kill the threads stuff now.

    I won't pretend that I wasn't a bit curious to play with threads. However, if this is is a bad practice then lesson learned and I'll go another route.


    dsb
    This @ISA my( $cool ) %SIG
      What I mean is that if the program is in the middle of processing the 3rd element in the stack and it receives an interrupt signal, I'd like it to finish the 3rd element and ONLY the third element before it exits.
      my $stop = 0; $SIG{whatever} = sub {$stop = 1 }; while(@stack and !$stop) { process(shift @stack); ... }

      Dave.

        I would not put the 'stop' in the while statement, but put it at the end of the loop block, so to do an 'exit if $stop'...

        Go Fish!

Log In?
Username:
Password:

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

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

    No recent polls found