Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.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 导入时生成新线程_Python_Multithreading_Import_Restriction - Fatal编程技术网

Python 导入时生成新线程

Python 导入时生成新线程,python,multithreading,import,restriction,Python,Multithreading,Import,Restriction,Python的状态: 除了在主模块中之外,导入不应该有边 产生一个新线程,然后在中等待该线程的效果 无论如何。不遵守此限制可能导致僵局 如果生成的线程直接或间接尝试导入 模块 我正在寻找演示此限制的示例代码。我尝试了此模块,该模块生成一个线程,其目标尝试导入sys: from threading import Thread def my_target(): import sys thread = Thread(target=my_target) thread.start() thre

Python的状态:

除了在主模块中之外,导入不应该有边 产生一个新线程,然后在中等待该线程的效果 无论如何。不遵守此限制可能导致僵局 如果生成的线程直接或间接尝试导入 模块


我正在寻找演示此限制的示例代码。

我尝试了此模块,该模块生成一个线程,其目标尝试导入
sys

from threading import Thread

def my_target():
    import sys

thread = Thread(target=my_target)
thread.start()
thread.join()

当启动python解释器并尝试导入上面的模块时,它确实会冻结。

这不是因为模块导入通常不是线程安全的吗?@DanD.-实际上,文档还说:
虽然导入机制是线程安全的,但由于固有的限制,线程导入有两个关键限制…
线程化
在重新导入时有两个限制-我问了一个相关的问题