in reply to Re: Threads Problem!
in thread Threads Problem!

I've tried forks and it works but it doesnt exit the sub the same way as threads do.


The bot is built on Net::IRC

Averything is handle with public commands wiht on_public.

For example a stock exchange checker.

i do  .stock ericsson from irc.
Then the bot jumps to a sub and does a alot of prosessing for me and print output to irc. after that is done i just want the sub to die. But this sub just keep goin as another prossess, or they still stay in system like zombies if i kill them. (ps -x)
i've tried exit(0); return; and also join but nothing gets it goin as it does with threads.

I probably don't have enuff knowledge to see what the problem is either :(

All i want is a sub thats runs parallell to other subs and when the sub is done it should just dissapear. Been trying to fix this for 1 month now but no luck :/

The entire script are made around threads It's 14 371 rows of code in 19 files so rewriting it from scratch would suck hehe

Someone said that POE::WHEEL could handle it to but i'm not sure. i just want a easy replacement for threads, forks would be real nice if i just could exit the subs the same way as threads does.

Thank you for your time. Really appreciate it.

Replies are listed 'Best First'.
Re: Re: Re: Threads Problem!
by liz (Monsignor) on Nov 03, 2003 at 14:34 UTC
    I've tried forks and it works but it doesnt exit the sub the same way as threads do.

    Could you elaborate on this? It should behave the same as threads. And I have not been able to reproduce it with a simple case. Are you sure they are zombies? Could it not be that something is keeping the forked processes alive in e.g. a DESTROY subroutine?

    Liz

      Sorry but i it's real hard to explain.

      Now i'm trying forks. It's actually working real good the only problem is that it doesnt exits the sub routines.

      Say my script is test.pl

      When someone does !help on irc in channel it starts my help sub

      then a ps -x shows another test.pl that confirms that the sub is running. When the sub is done it doesnt kill the newly created test.pl

      So after 300 ppl have done !help there are 300 test.pl running :)

      If i end the sub with exit; the entire script dies.

      Using threads with same script it starts a thread (a new test.pl shows in ps -x) after its done the extra test.pl dissapears just as i want it, but with this code i got the severe memory leak

      So i'm pretty close now i think :) just need it to exit the sub correctly so it closes.

      I start the sub with this syntax.

      $helpthr = threads->new(\&help, "$ircnick"); $helpthr->detach;
      I have tried to end the help sub with exit; and return; all it does is kill the entire bot,
      It only works if i restart the irc loop when the sub ends with
      $irc->start();


      Thank you yet again for taking time to help me.
        If you think exiting is the problem, you might want to have a look at Thread::Exit. However, I doubt whether that will make any diifference.

        Please try to re-create the problem with as little source as possible. I cannot reproduce the behaviour on my systems, so it must be something specific to your situation that is causing the zombies.

        What OS are you using anyway? Maybe the problem is OS related.

        Liz