释放另一个进程占用的资源

发布于 2024-10-11 21:42:54 字数 448 浏览 6 评论 0原文

在 SimPy 中,如果我已处理 ab 和资源 r 并执行以下操作:

yield request, self, r #request done in process a

如何从进程 b 释放资源?

yield release, a, r #release done in b (being a an instance of class a), doesn't work

我也尝试过:

r.activeQ.remove(a)

它实际上从活动队列中删除,但是它不会执行执行 yield 时执行的所有隐式步骤,结果证明这是毫无意义的。

能做到吗?如果是,怎么办?

In SimPy, if I've process a, b and resource r and do:

yield request, self, r #request done in process a

How can I release the resource from process b?

yield release, a, r #release done in b (being a an instance of class a), doesn't work

I've also tried:

r.activeQ.remove(a)

And it actually removes from the active queue, however it won't do all the implicit steps made when doing a yield and it turns out to be kind of pointless.

Can it be done? if yes, how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画骨成沙 2024-10-18 21:42:54

好吧,我的问题是进程 b 实际上处于非活动状态,因此任何yield 调用都会失败。

我想出的一个解决方法是

activate(a, a.function()) #called from process b

希望

class a(Process):
    def function(self):
        yield release, self, r
        yield passivate, self

这可以帮助任何遇到同样问题的人。

Well, my problem was process b was actually inactive and therefore any yield call would be unsuccessful.

A workaround I came up with was

activate(a, a.function()) #called from process b

Where

class a(Process):
    def function(self):
        yield release, self, r
        yield passivate, self

Hope this can help anyone out there having the same problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文