用Python命名的信号量? [英] Named semaphores in Python?

查看:164
本文介绍了用Python命名的信号量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中有一个脚本,该脚本使用的资源不能被正在运行的一定数量的并发脚本使用.

I have a script in python which uses a resource which can not be used by more than a certain amount of concurrent scripts running.

通常,这可以通过命名信号量来解决,但是我在 multiprocessing 模块或线程.

Classically, this would be solved by a named semaphores but I can not find those in the documentation of the multiprocessing module or threading .

我是否缺少某些东西或未由Python实现/公开的命名信号量?更重要的是,如果答案是否定的,那么模仿它的最佳方法是什么?

Am I missing something or are named semaphores not implemented / exposed by Python? and more importantly, if the answer is no, what is the best way to emulate one?

谢谢, 波阿斯

PS.由于与这个问题无关的原因,我无法将任务聚合到一个连续运行的进程/守护进程中,也无法将其与生成的进程一起使用-看来这两个都可以与python API一起使用.

PS. For reasons which are not so relevant to this question, I can not aggregate the task to a continuously running process/daemon or work with spawned processes - both of which, it seems, would have worked with the python API.

推荐答案

我建议使用第三方扩展程序,例如这些,最好是posix_ipc-尤其请参见 sempahore 部分在文档中.

I suggest a third party extension like these, ideally the posix_ipc one -- see in particular the sempahore section in the docs.

这些模块主要用于以统一的方式公开系统V IPC"(包括信号量),但是据称其中至少有一个(特别是posix_ipc)可以在Windows上与Cygwin一起使用(我尚未验证)该声明).在FreeBSD 7.2和Mac OSX 10.5上有一些已记录的限制,因此请注意那些平台对您很重要.

These modules are mostly about exposing the "system V IPC" (including semaphores) in a unixy way, but at least one of them (posix_ipc specifically) is claimed to work with Cygwin on Windows (I haven't verified that claim). There are some documented limitations on FreeBSD 7.2 and Mac OSX 10.5, so take care if those platforms are important to you.

这篇关于用Python命名的信号量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆