1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Disable progress bar when forking processes

This commit is contained in:
Brown 2019-05-30 15:15:12 -04:00
parent 1774d4029b
commit 8fd59674a2
3 changed files with 24 additions and 31 deletions

View File

@ -75,6 +75,7 @@
<UnusedClass> <UnusedClass>
<errorLevel type="suppress"> <errorLevel type="suppress">
<directory name="examples"/> <directory name="examples"/>
<directory name="src/Psalm/Internal/Fork" />
<file name="src/Psalm/Plugin/Shepherd.php" /> <file name="src/Psalm/Plugin/Shepherd.php" />
<file name="src/Psalm/Plugin/Hook/MethodReturnTypeProviderInterface.php"/> <file name="src/Psalm/Plugin/Hook/MethodReturnTypeProviderInterface.php"/>
</errorLevel> </errorLevel>

View File

@ -8,7 +8,6 @@ class ForkTaskDoneMessage implements ForkMessage
/** /**
* @param mixed $data * @param mixed $data
* @psalm-suppress PossiblyUnusedMethod
*/ */
public function __construct($data) public function __construct($data)
{ {

View File

@ -138,8 +138,7 @@ class Pool
$results = $shutdown_closure(); $results = $shutdown_closure();
// Serialize this child's produced results and send them to the parent. // Serialize this child's produced results and send them to the parent.
$process_done_message = new ForkProcessDoneMessage($results ?: []); $serialized_message = serialize($results ?: []);
$serialized_message = base64_encode(serialize($process_done_message)) . PHP_EOL;
fwrite($write_stream, $serialized_message); fwrite($write_stream, $serialized_message);
fclose($write_stream); fclose($write_stream);
@ -217,8 +216,6 @@ class Pool
/** @var array<int, string> $content */ /** @var array<int, string> $content */
$content = array_fill_keys(array_keys($streams), ''); $content = array_fill_keys(array_keys($streams), '');
$terminationMessages = [];
// Read the data off of all the stream. // Read the data off of all the stream.
while (count($streams) > 0) { while (count($streams) > 0) {
$needs_read = array_values($streams); $needs_read = array_values($streams);
@ -239,40 +236,36 @@ class Pool
$content[intval($file)] .= $buffer; $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 the stream has closed, stop trying to select on it.
if (feof($file)) { 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); fclose($file);
unset($streams[intval($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
)
);
} }
/** /**