in reply to Expect spawn_id and threads

Without showing the code, I suspect that one of your threads is calling exit. If any thread (including main thread) calls exit, the whole program exits taking everything with it. Try putting a <>; as the very last line of your main script, so it will hold on until you hit a key to exit.

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

Replies are listed 'Best First'.
Re^2: Expect spawn_id and threads
by lakputcha (Initiate) on Apr 03, 2008 at 12:50 UTC
    Sorry all, can't share code. As far exit in the code is concerned. I am not calling exit at all. Subroutine is only return 1 for Success and 0 for false. I have put <> in my main code and still observed the same behavior. I have used http://www.xav.com/perl/lib/Pod/perlthrtut.html to understand how Perl Threads work. Is there any other website with more details?
      If you are not calling exit, maybe you are calling die somewhere? Just google the SuperSearch here for threads, and you will find hundreds of real world thread problems with Perl. The big problem is thread-safety. Since your original node said

      s there a way to stop the thread->join from closing all spawn_ids?

      I would suspect that there is a thread safety issue where your threads are getting confused as to who "owns" what code. Part of thread safety is to try and isolate objects into their respective threads, so they don't get crossed linked( when a thread is spawned it gets an exact copy of the parent thread at the time of spawning, so you often CANNOT spawn threads at any time, because the new thread will a copy of all of the previously spawned threads). Anyways, since you are not willing to show a code example, we can't spot any obvious mistakes. You might want to try fork-and-exec rather than threads if you are having trouble. See parallel ssh or you might want to try Net::SSH2 which is supposedly thread safe. Also try googling for "perl Net::SSH2 thread safe" and see what others have tried. You may need an pty , see scp progress logging.

      The safest way for you to do this may be to spawn your 3 threads right at the start of your program, then pass in the expect ssh stuff in string to be eval'd in each thread, using shared variables.


      I'm not really a human, but I play one on earth. Cogito ergo sum a bum
        "when a thread is spawned it gets an exact copy of the parent thread at the time of spawning". You pointed out an interesting information. I am initializing all the connections in the main loop and passing the expect string to the thread. Will re-work on this way of implementation, keeping in mind what you pointed about threads. Will definetely google the SuperSearch. You have been very kind. Iam sure you understand why I cannot share my code. Will keep you all posted if and when i get around this problem. thanks a tonne. LAK.