Hi!
Rocco Caputo wrote:
> I can't see anything obviously wrong in the bits of code you posted.
> Is it possible for you to post a small yet complete and runnable test
> case that exhibits the problem?
Yes, of course.
The appended code shows the problem.
On my machine it creates the following output:
[...]
Job started!
10: RSS
10: 5644
Job closed!
Job started!
11: RSS
11: 5648
Job closed!
Job started!
12: RSS
12: 5648
Job closed!
Job started!
13: RSS
13: 5648
Job closed!
Job started!
14: RSS
14: 5648
Job closed!
Job started!
15: RSS
15: 5652
Job closed!
[...]
Every sec (or Wheel::Run creation/destruction) there's 1K of memory lost.
Thank you!
Sebastian.
P.S: This example was named 'test.pl'. If you rename it, remember to correct
the 'program' variable - respective the '-C' parameter of the ps command.
---snip---snip---snip---snip---snip---snip---snip---snip---snip---snip---snip
#!/usr/bin/perl
package RunGrep;
use 5.006;
use strict;
use warnings;
use vars qw($VERSION @ISA);
use POE;
use POE::Wheel::Run;
$VERSION=0.1;
sub create()
{
my( $class, $params ) = @_;
POE::Session->create(
args => [ $params ],
inline_states => {
_start => \&start,
run => \&run,
run_close => \&run_close,
run_stdout => \&run_stdout,
}
);
}
sub start
{
my ($kernel, $heap, $params, $this) = @_[KERNEL, HEAP, ARG0, ARG1];
$heap->{'params'} = $params;
$kernel->yield( 'run' );
}
sub run
{
my ($kernel, $heap) = @_[KERNEL, HEAP];
my $params = $heap->{'params'};
if( defined $heap->{'job'} )
{
print "Job collision!\n";
$kernel->delay( 'run', 5 );
return;
}
my $prog = $params->{'program'};
$heap->{'job'} = POE::Wheel::Run->new(
Program => $prog,
CloseEvent => 'run_close',
StdoutEvent => 'run_stdout',
);
print "Job started!\n";
if( $params->{'recurrence'} > 0 )
{
$kernel->delay( 'run', $params->{'recurrence'});
}
}
sub run_close
{
my ($kernel, $heap) = @_[KERNEL, HEAP];
print "Job closed!\n";
delete $heap->{'job'};
}
sub run_stdout
{
my ($kernel, $heap, $input, $wid) = @_[KERNEL, HEAP, ARG0, ARG1];
my $params = $heap->{'params'};
print "$wid: $input\n";
}
1;
use POE;
my $params = {
program => 'ps -C test.pl -o rss',
recurrence => '1'
};
RunGrep->create($params);
$poe_kernel->run();