On Wed, Oct 03, 2001 at 03:50:01AM -0700, H. Eising wrote:
> Hi all
> 
> I had a botscript which used Net::IRC, but when I heard
> about P::C::IRC, I thought I have a look at it and liked it
> very much at once. So I wanted to convert the script to use this
> component. I got it converted fine mostly, only a few things I don't
> understand and need some help with.

[...]

Good morning!  Are you "poing" on IRC?  :)

Child processes will not be able to post events to their parents.
fork() is kind of funny that way; each process is actually a separate
copy of the other, and even in your old program, $self->privmsg()
didn't ever affect the parent program.  In the code you posted, each
"fork" of your IRC client shared a socket, but neither knew what the
other was doing.

I'm not sure that's your problem, though.

> sub some_routine {
>     $kernel = shift;
>     $kernel->post('ircbot','privmsg',$channel,"This is a test line");
>     ...
>     pid=fork();
>     if (not defined $pid) {
>        $kernel->post('ircbot','privmsg',$channel,"fork Failed!");
>     } elsif ($pid == 0) {
>        # we're the child
>        print "DEBUG: inside the child";
>        $kernel->post('ircbot','privmsg',$channel,"inside the child now");
>     } else {
>        # we're the parent
>        print "DEBUG: inside the parent";
>        $kernel->post('ircbot','privmsg',$channel,"inside the parent");
>     }
> }
>
> Everything works fine, the print statements work both inside parent &
> child, only thing that doesn't work is the kernel->post inside the
> child, the message doesn't show up on IRC. Any clue on this, and how
> I should fix it to get it to work ? Seems like from inside the child I
> can't send anything to the POE::Component::IRC. I was told I shouldn't use
> fork unless there's no POE-able way to do somethin, but I'm not sure
> how I would do this otherwise.

[...]

Does "This is a test line" get sent to the channel?

Did you look at POE::Wheel::Run?  Its purpose is to run things in
child processes and pass the results back to the parent.
POE::Component::MPG123 uses it.

Did you look at <http://poe.perl.org/?POE_Cookbook/DBI_Helper_Processes>?
It has an example of using POE::Wheel::Run to do long-term DBI (database)
operations in a child process.  That might be similar to what you want.

Do you exit immediately after the post() in the child process?  That
will not work.

Do you leave the child process running afterwards?  That will
eventually be really really bad.

What exactly are you doing that takes so long?  Does it really need to
be done in a child process?

-- Rocco Caputo / [EMAIL PROTECTED] / poe.perl.org / poe.sourceforge.net

Reply via email to