with lock:
with db_con:
with socket:
#do stuff
但有没有办法在一个街区内完成呢?类似的
with lock,db_con,socket:
#do stuff
此外,是否有可能,给定一个具有上下文管理器的对象长度未知的数组,是否有可能以某种方式做到:
a=[lock1, lock2, lock3, db_con1, socket, db_con2]
with a as res:
#now all objects in array are acquired
如果答案是“否”,是否因为需要这样的功能意味着糟糕的设计,或者也许我应该在pep中建议它?: - p