首页
下载
文档
问答社区
视频
捐赠
源代码
AI 助理
赞助商
CRMEB
Apipost
腾讯云
微擎
禅道
51Talk
商业产品
Swoole AI 智能文档翻译器
Swoole-Compiler PHP 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
Process\Pool的detach不生效
### 问题描述 ### Swoole版本,PHP版本,以及操作系统版本信息 swoole:4.8.11 php:7.4 os:centos ### 相关代码 ```php <?php use Swoole\Process; use Swoole\Coroutine; $pool = new Process\Pool(2); $pool->set(['enable_coroutine' => true]); $pool->on('WorkerStart', function (Process\Pool $pool, $workerId) { static $running = true; Process::signal(SIGTERM, function () use (&$running) { $running = false; echo "TERM\n"; }); echo("[Worker #{$workerId}] WorkerStart, pid: " . posix_getpid() . "\n"); $i = 0; while ($running) { Coroutine::sleep(1); $i++; if ($i == 5) { $pool->detach(); } elseif ($i == 10) { break; } } }); $pool->on('WorkerStop', function (Process\Pool $pool, $workerId) { echo("[Worker #{$workerId}] WorkerStop, pid: " . posix_getpid() . "\n"); }); $pool->start(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? detach后并程序没有终止而且出现警告 ``` [Worker #0] WorkerStart, pid: 58222 [Worker #1] WorkerStart, pid: 58223 [Worker #0] WorkerStart, pid: 58224 [Worker #1] WorkerStart, pid: 58225 [Worker #0] WorkerStop, pid: 58222 [2023-04-28 11:30:00 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58222] [Worker #0] WorkerStart, pid: 58226 [Worker #1] WorkerStop, pid: 58223 [2023-04-28 11:30:00 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58223] [Worker #1] WorkerStart, pid: 58227 [Worker #0] WorkerStop, pid: 58224 [Worker #0] WorkerStart, pid: 58228 [2023-04-28 11:30:05 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58224] [Worker #1] WorkerStop, pid: 58225 [2023-04-28 11:30:05 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58225] [Worker #1] WorkerStart, pid: 58229 [Worker #0] WorkerStop, pid: 58226 [2023-04-28 11:30:10 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58226] [Worker #0] WorkerStart, pid: 58230 [Worker #1] WorkerStop, pid: 58227 [2023-04-28 11:30:10 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58227] [Worker #1] WorkerStart, pid: 58231 [Worker #0] WorkerStop, pid: 58228 [Worker #0] WorkerStart, pid: 58232 ...... ```
发布于1年前 · 8 次浏览 · 来自
提问
jesse-coder
### 问题描述 ### Swoole版本,PHP版本,以及操作系统版本信息 swoole:4.8.11 php:7.4 os:centos ### 相关代码 ```php <?php use Swoole\Process; use Swoole\Coroutine; $pool = new Process\Pool(2); $pool->set(['enable_coroutine' => true]); $pool->on('WorkerStart', function (Process\Pool $pool, $workerId) { static $running = true; Process::signal(SIGTERM, function () use (&$running) { $running = false; echo "TERM\n"; }); echo("[Worker #{$workerId}] WorkerStart, pid: " . posix_getpid() . "\n"); $i = 0; while ($running) { Coroutine::sleep(1); $i++; if ($i == 5) { $pool->detach(); } elseif ($i == 10) { break; } } }); $pool->on('WorkerStop', function (Process\Pool $pool, $workerId) { echo("[Worker #{$workerId}] WorkerStop, pid: " . posix_getpid() . "\n"); }); $pool->start(); ``` ### 你期待的结果是什么?实际看到的错误信息又是什么? detach后并程序没有终止而且出现警告 ``` [Worker #0] WorkerStart, pid: 58222 [Worker #1] WorkerStart, pid: 58223 [Worker #0] WorkerStart, pid: 58224 [Worker #1] WorkerStart, pid: 58225 [Worker #0] WorkerStop, pid: 58222 [2023-04-28 11:30:00 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58222] [Worker #0] WorkerStart, pid: 58226 [Worker #1] WorkerStop, pid: 58223 [2023-04-28 11:30:00 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58223] [Worker #1] WorkerStart, pid: 58227 [Worker #0] WorkerStop, pid: 58224 [Worker #0] WorkerStart, pid: 58228 [2023-04-28 11:30:05 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58224] [Worker #1] WorkerStop, pid: 58225 [2023-04-28 11:30:05 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58225] [Worker #1] WorkerStart, pid: 58229 [Worker #0] WorkerStop, pid: 58226 [2023-04-28 11:30:10 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58226] [Worker #0] WorkerStart, pid: 58230 [Worker #1] WorkerStop, pid: 58227 [2023-04-28 11:30:10 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58227] [Worker #1] WorkerStart, pid: 58231 [Worker #0] WorkerStop, pid: 58228 [Worker #0] WorkerStart, pid: 58232 ...... ```
赞
0
分享
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
评论
2023-04-29
Rango
`detach` 只是让 `Pool` 创建一个新的工作进程,当前的进程自生自灭。但无法解除父子进程的关联关系,因此当 `detach` 的进程退出时,管理进程依然会收到进程退出的信号,然后执行 `wait` 回收资源。这时管理进程在工作进程表中无法找到此进程(因为已经 `detach` 了),就会抛出上面的错误消息: ```shell [2023-04-28 11:30:10 @58221.0] WARNING ProcessPool::wait(): [Manager]unknown worker[pid=58227] ``` 这是符合预期的。同理,如果正常的 `worker` 进程又 `fork` 了一个新的孙进程,然后它自己退出,这时孙进程会被管理进程接管,当孙进程退出时,也会因为在工作进程表中无法找到而抛出上面的错误。
赞
0
回复
微信公众号
热门内容
暂无回复的问答
- CodeGalaxy K3s 轻量集群节点之间如何实现负载均衡
- 关于openssl CURL WARNING swSSL_connect: SSL_connect(fd=69) failed. Error: error:141A318A:SSL routines:tls_process_ske_dhe:dh key too small[1|394]
- 多个模型如何进行事务异常回退?
- websocket开启wss报错
- 协程tcp服务器如何使用多进程?recv()方法接收信息,打印出来的pid一直是同一个。没用使用到多进程啊。