Python:在线程中运行函数不会修改current_thread() [英] Python : Running function in thread does not modify current_thread()

查看:177
本文介绍了Python:在线程中运行函数不会修改current_thread()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在试图弄清线程在python中的工作方式.

I'm currently trying to figure out how threads work in python.

我有以下代码:

def func1(arg1, arg2):

    print current_thread()
    ....

class class1:

    def __init__():
        ....

    def func_call():
        print current_thread()
        t1 = threading.Thread(func1(arg1, arg2))
        t1.start()
        t1.join()

我注意到的是,两个打印输出的都是相同的东西.为什么线程没有更改?

What I noticed is that both prints output the same thing. Why is the thread not changing?

推荐答案

您正在执行该函数,而不是传递它.尝试以下方法:

You're executing the function instead of passing it. Try this instead:

t1 = threading.Thread(target = func1, args = (arg1, arg2))

这篇关于Python:在线程中运行函数不会修改current_thread()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆