Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 线程:join()永远不会返回_Python_Multithreading - Fatal编程技术网

Python 线程:join()永远不会返回

Python 线程:join()永远不会返回,python,multithreading,Python,Multithreading,我正在尝试创建多个线程,将它们添加到一个列表中,遍历该列表,然后像这样加入每个线程: threads = [] for i in range(0, 4): new_thread = threading.Thread(target=Runnable()) new_thread.start() threads.append(new_thread) for thread in threads: print("in thread") print(thread)

我正在尝试创建多个线程,将它们添加到一个列表中,遍历该列表,然后像这样加入每个线程:

threads = []
for i in range(0, 4):
    new_thread = threading.Thread(target=Runnable())
    new_thread.start()
    threads.append(new_thread)
for thread in threads:
    print("in thread")
    print(thread)
    thread.join()
    print("after join")

它将打印“In-thread”和线程,但它从不打印“after-join”,因此我的所有代码after都不会运行
Runnable()
是我创建的一个函数,它也会打印它应该打印的内容,因此我不确定该代码是否与它有任何关系。

在创建每个
线程
实例时调用
Runnable
,因此线程的
目标
函数是它返回的任何内容(可能
)。尝试使用:

new_thread = threading.Thread(target=Runnable)

它具有
target=Runnable
而不是
target=Runnable()。尝试使用:

new_thread = threading.Thread(target=Runnable)

哪个函数的
target=Runnable
而不是
target=Runnable()

您的Runnable()函数是否返回过?否。它执行一些操作,然后向队列中添加一条记录,我稍后使用。这并不意味着返回任何内容。请考虑添加
runnable
代码。
runnable
是否曾经结束过?是创建一个要运行的对象,还是它只是开始做一些事情?(整个
Runnable
听起来像是一个不必要的Java设计。)您的Runnable()函数是否返回过?否。它做了一些事情,然后向队列中添加一条记录,稍后我会使用它。这并不意味着返回任何内容。请考虑添加
runnable
代码。
runnable
是否曾经结束过?是创建一个要运行的对象,还是它只是开始做一些事情?(整个
Runnable
听起来像是一个不必要的Java设计。)