graze / parallel-process

:running: Run multiple processes simultaneously
MIT License
103 stars 23 forks source link

Process Output #11

Closed cjsfj closed 7 years ago

cjsfj commented 7 years ago

Greetings -

Perhaps I'm missing something, but I am trying to see if it is possible to see the stdout of each process that is run in the pool.

Thanks,

C

h-bragg commented 7 years ago

Hi,

Thanks for the comment!

Not out of the box, but that is a good idea. Currently there is the onProgress call but it doesn't guarantee to get every line (it probably should, and it should determine the difference between stderr and stdout).

Ill look into adding something.

Currently you can do:

$pool = new Pool([$p1, $p2]);
$pool->setOnProgress(function (Process $process, float $duration, string $last) {
    printf("[pid:%d] %s", $process->getPid(), $last);
});

But it might miss some output, and will not differentiate between stdout and stderr.

I think I might change it to:

$pool = new Pool([$process1, $process2]);
$pool->setOnProgress(function (Process $process, float $duration, string $type, string $data) {
    printf("[pid:%5d] (%s) %s", $process->getPid(), $type, $data);
});
$pool->run();

Which would produce something like:

[pid:  123] (err) Some text 
[pid: 2412] (std) Some standard output

And add a different type of Console Output class to write it out with different colours and tags for each process.

cjsfj commented 7 years ago

Thanks for the quick response! I'll see what I can do with these examples.

Thinking through my use case... running 10 simultaneous processes, one would not necessarily know the PID of each process. So maybe at the beginning also have a way to print the pid:process command relationships?

Thank you again!

C

h-bragg commented 7 years ago

The PR: #12 should do what you need to do... You supply a set of tags for each process you add, these then get outputted for each process so you can tell them apart.

cjsfj commented 7 years ago

This looks good to me so far! Thank you!