我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用gevent.local()。
def test_local(self): """ ?????? ?????gevent?web???HTTP?????????????????gevent? """ stash = local() def f1(): stash.x = 1 print(stash.x) def f2(): stash.y = 2 print(stash.y) try: stash.x except AttributeError: print("x is not local to f2") g1 = gevent.spawn(f1) g2 = gevent.spawn(f2) gevent.joinall([g1, g2])
def f2(): stash.y = 2 print(stash.y) try: stash.x except AttributeError: print('x is not local to f2') # second
def f2(): stash.y = 2 print(stash.y) try: stash.x except AttributeError: print("x is not local to f2")