Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is this possible to solve without using perl threads?

Status
Not open for further replies.

Phantazm

Technical User
Nov 3, 2003
6
SE
Hi. I got a huge problem with a irc bot i've built. Today i use threads but it's almost impossible to live with due to the memory leaking problem. Is there another tool that can work almost the same as threads. For a brief examle: (a on public sub)

if (lc substr($text,0,5) eq ".help") {
my $info = substr($text,6);
my $auth = autcheck($info, $event->{nick}, $event->{host});
$helpthr = threads->new(\&help);
$helpthr->detach;
}

This is just an example where i tread the help sub. Sometimes i have HUGE subs running on public commands, some takes about 30 mins to complete. Thats why i need threads so the main code wont be locked up and wait for the sub to exit. So ppl can run parallell, Say 5 ppl type help at the same time they should all be served directly.
Is there any other "simple" way to do this? I've tried forks but that didnt work good at all. Been reading a little about POE but just can figure out if it could be a sollution to my problem or not.

Please help a desperate dude out here :)


--------

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.

-----

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();

-------

All this info is from another thread i've started in a diffrent forum.

Getting really desperate here hehe.

Thanx for reading!
 
Thanx but it's forks (same api as threads) i've tried.

Alsoe the POE looks intresting but i just cant figure out where to start :/ might have built this bot to advanced for my self haha

Just ned to run a sub parallell
like

gosub($var);

how can i make that sub not look up the main script and also be able to run in multiple sessions.

What i need is another variant of
async {
gosub($var);
};

That doesn use threads

:/


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top