From 2c7e938b9f2f5fb99773f04fe6a385a1ae38cb68 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Sat, 27 Feb 2021 04:45:42 +0800 Subject: [PATCH] modify --- HttpServer/Events/OnWorkerStart.php | 37 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/HttpServer/Events/OnWorkerStart.php b/HttpServer/Events/OnWorkerStart.php index 752d37ee..2b4aff54 100644 --- a/HttpServer/Events/OnWorkerStart.php +++ b/HttpServer/Events/OnWorkerStart.php @@ -36,28 +36,31 @@ class OnWorkerStart extends Callback */ public function onHandler(Server $server, int $worker_id): void { - Coroutine::set([ - 'enable_deadlock_check' => false, - 'exit_condition' => function () { - return Coroutine::stats()['coroutine_num'] === 0; - } - ]); +// Coroutine::set([ +// 'enable_deadlock_check' => false, +// 'exit_condition' => function () { +// return Coroutine::stats()['coroutine_num'] === 0; +// } +// ]); $get_name = $this->get_process_name($server, $worker_id); if (!empty($get_name) && !Snowflake::isMac()) { swoole_set_process_name($get_name); } - -// Coroutine\go(function ($server, $worker_id) { -// $sigkill = Coroutine::waitSignal(SIGTERM | SIGKILL | SIGUSR2 | SIGUSR1); -// if ($sigkill !== false) { -// return $server->stop(); -// } -// while (Snowflake::app()->isRun()) { -// Coroutine::sleep(0.01); -// } -// return $server->stop(); -// }, $server, $worker_id); + Coroutine\go(function (Server $server, $worker_id) { + $sigkill = Coroutine::waitSignal(SIGTERM | SIGKILL | SIGUSR2 | SIGUSR1); + if ($sigkill !== false) { + return Process::kill($server->worker_pid); + } + do { + $number = Coroutine::stats()['coroutine_num']; + if ($number === 0) { + break; + } + Coroutine::sleep(0.01); + } while (true); + return Process::kill($server->worker_pid); + }, $server, $worker_id); $name = ($worker_id >= $server->setting['worker_num'] ? 'Task' : 'Worker'); $this->debug(sprintf($name . ' #%d is start.....', $worker_id));