Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Opposite.

I am running a program, based on POE::Component::Daemon::Win32,it is a service. It is spawning children with POE::Wheel::Run::Win32.

Yes, I tell SCM that I have started OK.
And yes, everything works fine, when started from the command line ( c:> perl service.pl )
Moreover, the spawned child runs OK and returns. And after it returns, the system calls my STOP_PENDING callback. I see that message in the log.

I also tried using POE::Wheel::Run (without Win32) - same thing.

Here is the exclications from my code. I will try not to include anything that is not needed.

use Win32; use Win32::SqlServer; use Win32::Daemon; use POE::Component::JobQueue; use POE::Component::Log4perl; use POE::Component::Daemon::Win32; use POE qw( Wheel::Run::Win32 Filter::Line); sub _start { my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; chdir $workdir; POE::Component::Log4perl->spawn( Alias => 'logger', Category => 'default', ConfigFile => $config ); POE::Component::Daemon::Win32->spawn ( Callback => { not_ready => \&service_default_callback, start_pending => \&service_start_pending, running => \&service_running, pause_pending => \&service_default_callback, paused => \&service_default_callback, continue_pending=> \&service_default_callback, stop_pending => \&service_stop_pending, stoppped => \&service_stopped, shutdown => \&service_shutdown } ); POE::Component::JobQueue->spawn ( Alias => 'queue', WorkerLimit => $max_jobs, Worker => \&make_a_worker, Active => { PollInterval => $poll_interval } ); } sub _stop { POE::Kernel->call('logger'=>info=>"service stopped"); } sub service_stop_pending { POE::Kernel->post('logger'=>debug=>"call to stop_pending"); POE::Kernel->yield('next_state'); } sub service_running{ POE::Kernel->yield('next_state'); } #### other callbacks are similar, all yield('next_state') sub make_a_worker { my $meta_postback = shift; my $file_name = shift @file_queue; POE::Session->create( inline_states => { _start => \&worker_start, _stop => sub { }, worker_child_stdout => \&worker_child_stdout, worker_closed_ffmpeg=> \&worker_closed_ffmpeg, worker_closed_asr => \&worker_closed_asr, sig_child => \&sig_child }, args => [ $postback, $file_name ] ); } sub worker_start { my ($kernel, $session, $heap, @args ) = @_[KERNEL, SESSION, HEAP, +ARG0 .. $#_]; $heap->{postback} = $args[0]; $heap->{cmdline} = POE::Wheel::Run::Win32->new( Program => $ffmpeg, ProgramArgs => \@ffmpeg_args, StdoutEvent => "worker_child_stdout", StderrEvent => "worker_child_stdout", CloseEvent => "worker_closed_ffmpeg", StdioFilter => POE::Filter::Line->new(), # Child speaks in + lines. StderrFilter => POE::Filter::Line->new(), # Child speaks in + lines. ); $kernel->sig_child($heap->{cmdline}->PID, "sig_child"); POE::Kernel->post('logger'=>info=>"session ".$session->ID." start +ffmpeg ".join(' ',@ffmpeg_args)); } sub worker_child_stdout ### processes the output of the ffmpeg and pu +ts the lines to the log, I can see - ffmpeg is running. sub sig_child { my ( $heap, $sig, $pid, $exit_val ) = @_[ HEAP, ARG0, ARG1, ARG2 ] +; my $d = delete $heap->{cmdline} if $exit_val; POE::Kernel->post('logger'=>debug=>"session ".$heap->{SessionID}." + sig_child: sig=$sig, pid=$pid, exit_val=$exit_val"); print "sig_child: sig=$sig, pid=$pid, exit_val=$exit_val\n"; return 0; } my @handlers = qw( _start _stop ); POE::Session->create( package_states => [ main => \@handlers ] ); POE::Kernel->run(); POE::Kernel->call( 'queue' => 'stop' ); exit 0; __END__

In reply to Re^2: Win32 daemon in POE by wl2776
in thread Win32 daemon in POE by wl2776

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-04-24 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found