From c9f7c966fcdaf0fef496adf72a9a2493d6fe2bb1 Mon Sep 17 00:00:00 2001 From: Alex Turchak Date: Fri, 10 Jan 2020 14:21:27 +0200 Subject: [PATCH] [master-stop-child-process] Child process is not stop when we call method `markAsTimedOut` it continue work on background - Added call stop method in markAsTimedOut - Added possibility modify timeout --- src/Pool.php | 5 +++-- src/Process/ParallelProcess.php | 4 ++-- src/Process/Runnable.php | 7 ++++++- src/Process/SynchronousProcess.php | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Pool.php b/src/Pool.php index f1adb98c..fc40c0f1 100644 --- a/src/Pool.php +++ b/src/Pool.php @@ -207,11 +207,12 @@ public function markAsTimedOut(Runnable $process) { unset($this->inProgress[$process->getPid()]); - $this->notify(); + $process->stop(); $process->triggerTimeout(); - $this->timeouts[$process->getPid()] = $process; + + $this->notify(); } public function markAsFailed(Runnable $process) diff --git a/src/Process/ParallelProcess.php b/src/Process/ParallelProcess.php index 9637dcd2..d6508127 100644 --- a/src/Process/ParallelProcess.php +++ b/src/Process/ParallelProcess.php @@ -42,9 +42,9 @@ public function start(): self return $this; } - public function stop(): self + public function stop($timeout = 0): self { - $this->process->stop(10, SIGKILL); + $this->process->stop($timeout, SIGKILL); return $this; } diff --git a/src/Process/Runnable.php b/src/Process/Runnable.php index bc956f7a..542a2eef 100644 --- a/src/Process/Runnable.php +++ b/src/Process/Runnable.php @@ -31,7 +31,12 @@ public function catch(callable $callback); */ public function timeout(callable $callback); - public function stop(); + /** + * @param int|float $timeout The timeout in seconds + * + * @return mixed + */ + public function stop($timeout = 0); public function getOutput(); diff --git a/src/Process/SynchronousProcess.php b/src/Process/SynchronousProcess.php index fd2db310..3e3f6ada 100644 --- a/src/Process/SynchronousProcess.php +++ b/src/Process/SynchronousProcess.php @@ -53,7 +53,7 @@ public function start() } } - public function stop() + public function stop($timeout = 0): void { }