This commit is contained in:
2026-07-08 11:39:27 +08:00
parent 1f443958e8
commit 27ffa05515
6 changed files with 221 additions and 30 deletions
+18 -7
View File
@@ -17,6 +17,8 @@ abstract class AbstractProcess implements OnProcessInterface
private bool $stop = false;
private bool $stopping = false;
public Process $process;
@@ -132,10 +134,11 @@ abstract class AbstractProcess implements OnProcessInterface
$array['deadlock_check_disable_trace'] = false;
$array['exit_condition'] = [$this, 'exit_condition'];
Coroutine::set($array);
$process::signal(SIGINT, static function (): void {});
Coroutine::create(fn() => $this->coroutineWaitSignal());
} else {
$process::signal(SIGTERM, [$this, 'pointWaitSignal']);
$process::signal(SIGINT, [$this, 'pointWaitSignal']);
$process::signal(SIGINT, static function (): void {});
}
return $this;
}
@@ -153,9 +156,7 @@ abstract class AbstractProcess implements OnProcessInterface
*/
public function pointWaitSignal($signal): void
{
$this->stop = true;
$this->onSigterm();
$this->requestStop();
}
@@ -164,10 +165,20 @@ abstract class AbstractProcess implements OnProcessInterface
*/
public function coroutineWaitSignal(): void
{
$value = Coroutine::waitSignal(SIGTERM);
if ($value) {
$this->stop = true;
Coroutine::waitSignal(SIGTERM);
$this->requestStop();
}
private function requestStop(): void
{
if ($this->stopping) {
return;
}
$this->stopping = true;
$this->stop = true;
$this->onSigterm();
}