-
-
Notifications
You must be signed in to change notification settings - Fork 64
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
Regular output on stdout cut off after running parallel task #104
Comments
I guess |
Thanks for the fast answer! Is this something that should be added to this package or rather something I should add to my implementation? It is probably a better DX if the package cleans up the stream changes once it's done? |
Hmm… I'm not sure there's an easy way to know when we're done writing to STDOUT, as that doesn't happen in a single place and the assumption was made that you'd write to STDOUT using Amp's streams, accessible through If that doesn't work for you, I guess I would recommend setting blocking to true on STDOUT once you know you're done with Amp. The Worker API attempted to make parallelizing tasks simple with a very minimal API and to make debugging easy and obvious. One of the choices we made was piping STDOUT/STDERR to the main process. You can have much more control over the behavior of child processes/threads if you use the Context API, which allows you you write a script that is executed in parallel. |
Thanks for the detailed feedback! It are valid assumptions to make. |
We could probably provide some option to disable the automatic piping? |
That could be a nice solution to the problem as well... |
@veewee Do you want to provide a PR? |
Hello @kelunik, Any thoughts on how to implement this?
|
The environment class is meant to be used by tasks in the workers, so not suitable here, as we like to change the parent behavior. My first thought was a global toggle like a function that's toggleable, but initialized by an environment variable or so. But I think it's better to introduce some kind of StreamHandler interface, that can be used to disable or customize the piping behavior. The current piping happens in an internal class users shouldn't touch, but I guess we can pass such a stream handler down from DefaultPool.
Something like that maybe? <?php
interface OutputSink {
function getStdout(Worker $worker);
function getStderr(Worker $worker);
} |
Since I dont know the internals of this package well enough, I'm afraid adding the feature as you describe is a bit out of my league at the moment. |
@veewee Could you open another issue then, so we don't forget about it? |
Hello,
First things first: Thanks for your packages!
I'm trying to make a part of an existing tool async first.
However, when mixing parallel with regular symfony console output, the output gets cut off.
You can test it with this boilerplate code (assuming you have symfony/console in your dependencies)
I currently disabled the extensions, so parallel is using the internal php process implementation.
As you can see: the first output list is complete.
However, the second output list behaves in an inconsistent strange way.
For example:
From time to time, it also cuts off the end:
My best guess is that this is related to the output streams being piped to an amphp/byte-stream:
https://github.com/amphp/parallel/blob/master/lib/Worker/Internal/WorkerProcess.php#L47-L48
If I replace the Symfony code with a low-level php implementation, it fails in a more consistent way:
Do you have any suggestion on how to solve this issue or how to unpipe the streams after running the async actions?
The reporting of the tool I am writing is done by symfony console instead of amphp at the moment. Would love to keep it like that
(More context about the actual implementation is available here : phpro/grumphp#741 - but the provided snippet should be sufficient to reproduce)
The text was updated successfully, but these errors were encountered: