如何锁定Django中的关键部分? [英] How to lock a critical section in Django?

查看:104
本文介绍了如何锁定Django中的关键部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到一个很好的干净的方法来锁定Django中的关键部分。我可以使用锁或信号量,但python实现仅适用于线程,因此如果生产服务器提供了这些请求,那么它们就不会受到尊重。有人知道某种方式(我现在正在考虑posix信号量),以保证跨进程的锁定,或禁止一种方法来阻止Django服务器进行分割。

I can't find a good clean way to lock a critical section in Django. I could use a lock or semaphore but the python implementation is for threads only, so if the production server forks then those will not be respected. Does anyone know of a way (I am thinking posix semaphores right now) to guarantee a lock across processes, or barring that a way to stop a Django server from forking.

推荐答案

您的应用程序突然需要在多个服务上运行,您需要一个分布式锁管理器。为此写了 elock 。有较大的人,而其他人则选择忽略每个建议,并对memcached进行相同操作。

You need a distributed lock manager at the point where your app suddenly needs to run on more than one service. I wrote elock for this purpose. There are bigger ones and others have chosen to ignore every suggestion and done the same with memcached.

请勿使用memcached进行轻型咨询锁定。它被设计为忘记东西。

Please don't use memcached for anything more than light advisory locking. It is designed to forget stuff.

我喜欢假装像我在制作网络应用时文件系统不存在。使规模更好。

I like to pretend like filesystems don't exist when I'm making web apps. Makes scale better.

这篇关于如何锁定Django中的关键部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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