Skip to content
Permalink
Browse files

Disable progress bar when forking processes

  • Loading branch information...
muglug committed May 30, 2019
1 parent 1774d40 commit 8fd59674a25804db5e6c202462de8254e602ab6f
Showing with 24 additions and 31 deletions.
  1. +1 −0 psalm.xml.dist
  2. +0 −1 src/Psalm/Internal/Fork/ForkTaskDoneMessage.php
  3. +23 −30 src/Psalm/Internal/Fork/Pool.php
@@ -75,6 +75,7 @@
<UnusedClass>
<errorLevel type="suppress">
<directory name="examples"/>
<directory name="src/Psalm/Internal/Fork" />
<file name="src/Psalm/Plugin/Shepherd.php" />
<file name="src/Psalm/Plugin/Hook/MethodReturnTypeProviderInterface.php"/>
</errorLevel>
@@ -8,7 +8,6 @@ class ForkTaskDoneMessage implements ForkMessage
/**
* @param mixed $data
* @psalm-suppress PossiblyUnusedMethod
*/
public function __construct($data)
{
@@ -138,8 +138,7 @@ public function __construct(
$results = $shutdown_closure();
// Serialize this child's produced results and send them to the parent.
$process_done_message = new ForkProcessDoneMessage($results ?: []);
$serialized_message = base64_encode(serialize($process_done_message)) . PHP_EOL;
$serialized_message = serialize($results ?: []);
fwrite($write_stream, $serialized_message);
fclose($write_stream);
@@ -217,8 +216,6 @@ private function readResultsFromChildren()
/** @var array<int, string> $content */
$content = array_fill_keys(array_keys($streams), '');
$terminationMessages = [];
// Read the data off of all the stream.
while (count($streams) > 0) {
$needs_read = array_values($streams);
@@ -239,40 +236,36 @@ private function readResultsFromChildren()
$content[intval($file)] .= $buffer;
}
if (strpos($buffer, PHP_EOL) !== false) {
$serialized_messages = explode(PHP_EOL, $content[intval($file)]);
$content[intval($file)] = array_pop($serialized_messages);
foreach ($serialized_messages as $serialized_message) {
$message = unserialize(base64_decode($serialized_message));
if ($message instanceof ForkProcessDoneMessage) {
$terminationMessages[] = $message->data;
} elseif ($message instanceof ForkTaskDoneMessage) {
if ($this->task_done_closure !== null) {
($this->task_done_closure)($message->data);
}
} else {
error_log('Child should return ForkMessage - response type=' . gettype($message));
$this->did_have_error = true;
}
}
}
// If the stream has closed, stop trying to select on it.
if (feof($file)) {
if ($content[intval($file)] !== '') {
error_log('Child did not send full message before closing the connection');
$this->did_have_error = true;
}
fclose($file);
unset($streams[intval($file)]);
}
}
}
return array_values($terminationMessages);
return array_values(
array_map(
/**
* @param string $data
*
* @return array
*/
function ($data) {
/** @var array */
$result = unserialize($data);
/** @psalm-suppress DocblockTypeContradiction */
if (!\is_array($result)) {
error_log(
'Child terminated without returning a serialized array - response type=' . gettype($result)
);
$this->did_have_error = true;
}
return $result;
},
$content
)
);
}
/**

0 comments on commit 8fd5967

Please sign in to comment.
You can’t perform that action at this time.