Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Mojo::IOLoop::Subprocess trigger the same parent code at runtime #1054

Closed
ggl opened this issue Feb 15, 2017 · 1 comment
Closed
Labels

Comments

@ggl
Copy link

ggl commented Feb 15, 2017

  • Mojolicious version: 7.25
  • Perl version: 5.20.3
  • Operating system: Darwin Kernel Version 14.5.0: Sun Sep 25 22:07:15 PDT 2016; root:xnu-2782.50.9~1/RELEASE_X86_64 x86_64

Steps to reproduce the behavior

If you start multiple Mojo::IOLoop::Subprocess processes from a for loop, the parent code will get triggered for every one of the created children at every iteration of the loop. What's more annoying is that this is done with undef @results, triggering a Storable error (thaw with an empty buffer).

#!/usr/bin/env perl

use feature 'say';
use Mojo::IOLoop;
use Mojo::IOLoop::Subprocess;

# Operation that would block the event loop for 5 seconds
for (0..2) {
  my $subprocess = Mojo::IOLoop::Subprocess->new;
  $subprocess->run(
    sub {
      my $subprocess = shift;
      sleep 5;
      return '', 'Mojolicious';
    },
    sub {
      my ($subprocess, $err, @results) = @_;
      $pid = $subprocess->pid;
      say "Subprocess $pid error: $err" and return if $err;
      say "Subprocess $pid $results[0] $results[1]!";
    }
  );
}

# Start event loop if necessary
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

Expected behavior

The parent sub should only be executed once the current child returns.

Actual behavior

The parent code gets triggered once for every child spawned with the run method.

@ggl ggl changed the title Multiple Mojo::IOLoop::Subprocess trigger the same parent code Multiple Mojo::IOLoop::Subprocess trigger the same parent code at runtime Feb 15, 2017
@kraih kraih added the bug label Feb 15, 2017
@kraih
Copy link
Member

kraih commented Feb 15, 2017

Looks like a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants