This commit is contained in:
as2252258@163.com
2021-02-27 04:45:42 +08:00
parent 9868a6e219
commit 2c7e938b9f
+20 -17
View File
@@ -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));