Erlang/ets:在收到“错误参数”后重置 ets 表?
我一直在学习如何使用 ets,但困扰我的一件事是,偶尔*,ets:match
会抛出一个错误的参数
…而且,从他们开始,所有后续调用(甚至先前有效的调用)也会抛出错误参数:
> ets:match(Tid, { [$r | '$1'] }, 1). % this match works... % Then, at some point, this comes up: ** exception error: bad argument in function ets:match/3 called as ets:match(24589,{[114|'$1']},1) % And from then on, matches stop working: > ets:match(Tid, { [$r | '$1'] }, 1). ** exception error: bad argument in function ets:match/3 called as ets:match(24589,{[114|'$1']},1)
是否有任何方法可以“重置”ets 系统以便我可以查询它(即,来自外壳)再次?
*:我无法重现这个问题……但是当我尝试做“其他事情”时,这种情况经常发生。
I've been learning how to use ets, but one thing that has bothered me is that, occasionally*, ets:match
throws a bad argument
… And, from them on, all subsequent calls (even calls which previously worked) also throw a bad argument
:
> ets:match(Tid, { [$r | '$1'] }, 1). % this match works... % Then, at some point, this comes up: ** exception error: bad argument in function ets:match/3 called as ets:match(24589,{[114|'$1']},1) % And from then on, matches stop working: > ets:match(Tid, { [$r | '$1'] }, 1). ** exception error: bad argument in function ets:match/3 called as ets:match(24589,{[114|'$1']},1)
Is there any way to "reset" the ets
system so that I can query it (ie, from the shell) again?
*: I haven't been able to reproduce the problem… But it happens fairly often while I'm trying to do "other things".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我不是 100% 确定,此帖子似乎回答了你的问题。您似乎正在 shell 中观察到这种行为。如果是这样,则两个事实以令人困惑的方式相互作用:
因此,当您收到第一个异常时,当前 shell 进程会终止,导致 ets 表被删除,然后会为您启动一个新的 shell 进程。现在,当您尝试另一个
ets:match
时,它会失败,因为该表不再存在。Although I'm not 100% sure, this thread seems to answer your question. It appears that you're observing this behaviour in the shell. If so, two facts are interacting in a confusing way:
So, when you get the first exception, the current shell process dies causing the ets table to be deleted, and then a new shell process is started for you. Now, when you try another
ets:match
, it fails because the table no longer exists.戴尔已经告诉过你会发生什么。您可以通过在 shell 中不时调用 self() 来确认这一点。
作为一种快速解决方法,您可以生成另一个进程来为您创建公共表。那么那张桌子就不会和你的外壳一起死掉了。
现在破例并检查该表是否确实幸存下来。
要删除该表,只需向您生成的进程发送一些内容:
Dale already told you what happens. You can confirm that by calling self() in the shell every now and then.
As a quick workaround you can spawn another process to create a public table for you. Then that table won't die along with your shell.
Now make an exception and check that the table indeed survived.
To delete the table, just send something to your spawned process: