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])
python类local()的实例源码
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")