python类local()的实例源码

test_gevent.py 文件源码 项目:core-python 作者: yidao620c 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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])
15??????.py 文件源码 项目:Python_Study 作者: thsheep 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def f2():
    stash.y = 2
    print(stash.y)

    try:
        stash.x
    except AttributeError:
        print('x is not local to f2')

# second
test_10.py 文件源码 项目:notebook 作者: archever 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def f2():
    stash.y = 2
    print(stash.y)

    try:
        stash.x
    except AttributeError:
        print("x is not local to f2")


问题


面经


文章

微信
公众号

扫码关注公众号