【发布时间】:2019-08-05 23:38:24
【问题描述】:
我有一个 python 程序,它可能在任何时候被某个调度程序调用多次。
它按照某种模式生成一个字符串,我想确保这个字符串不是由同时运行的另一个进程生成的(锁定字符串)。如果是这样,它必须按照相同的模式生成一个新字符串,并再次检查 if 不存在。如果一个进程结束,相关的字符串可以被一个新的(解锁字符串)重用。
例子:
t=0
process 1 - "string_1"
t=1 (process_1 finished)
process 2 - "string_1"
process 3 - "string_2" (cause "string_1" already exists)
t=2 (process 2 and 3 still running)
process 4 - "string_3"
t=3 (procces 3 finished)
process 5 - "string_2"
and so on...
任何想法如何基于字符串实现这种“某种”系统范围的互斥锁?
【问题讨论】:
标签: python python-3.x mutex