名为timer_server的gen_server导致定时器模块函数不返回
我创建了一个主管,它生成了一个名为 timer_server
的 gen_server
。 这个timer_serve
r的任务之一是管理注册并调用timer:send_interval
以一定的时间间隔向pid发送消息。
但是,在 gen_server
的 init 中,我调用 timer:send_interval
时出现了锁定。 文档说计时器:函数立即返回,所以这非常麻烦。
当我将 gen_server
重命名为 record_timer_server
时,这个问题就解决了。 那么我的问题有两个:
- 如果我的应用程序启动时调用
timer:start()
时已经有一个注册进程timer_server
,为什么我可以创建一个注册进程呢? - 一旦启动,如果该函数使用
send_interval
函数调用我的timer_server
,为什么它不会导致名称不匹配?
我认为代码不是必需的,但如果需要,我可以更新以添加一些代码。
I created a supervisor that spawned a gen_server
I called timer_server
. One of the tasks of this timer_serve
r is to manage registration and call timer:send_interval
to send a message to a pid on a certain interval.
However, in the init of the gen_server
, where I call timer:send_interval
I was getting a lockup. The documentation said the timer: functions return immediately, so this was very troubling.
When I renamed my gen_server
to record_timer_server
this problem cleared up. My question is two fold then:
- Why could I create a registered process
timer_server
, if there already was one whentimer:start()
was called by my application starting up? - Once started, why would this function not cause a badmatch finding the name, if it was calling in to my
timer_server
using thesend_interval
function?
I don't think code is necessary but I can update to add some if requested.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需执行以下挂在对计时器的调用上即可重新创建:send_interval。
虽然这失败了......
所以,似乎对计时器的第一次调用尝试启动一个名为timer_server的进程,并且如果您首先使用该名称,则会挂起。
至于为什么它挂起,timer.erl 的作用是:
它返回很好,然后是 gen_server:对timer_server 的调用。 然后您的进程就会陷入等待自身响应的状态。
This can be recreated simply by doing the following which hangs on the call to timer:send_interval.
While this fails...
So, it seems that the first call to timer tries to start a process called timer_server, and hangs if you've taken this name first.
As to why it hangs timer.erl does:
which returns fine, followed by a gen_server:call to timer_server. Your process then gets stuck waiting for itself to respond.