Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.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:threading:adj';后台进程是否将stdin/stdout返回到主线程?_Python_Multithreading - Fatal编程技术网

Python:threading:adj';后台进程是否将stdin/stdout返回到主线程?

Python:threading:adj';后台进程是否将stdin/stdout返回到主线程?,python,multithreading,Python,Multithreading,我有一个简单的线程设置:生成一个后台子线程,然后等待键盘输入停止: MASTER = threading.Thread(target=QueueMonitor()) MASTER.setDaemon(True) MASTER.start() while True: ZZ = raw_input("running...\ntype 'ZZ' to quit \n\n") if 'ZZ' in ZZ: prin

我有一个简单的线程设置:生成一个后台子线程,然后等待键盘输入停止:

    MASTER = threading.Thread(target=QueueMonitor())
    MASTER.setDaemon(True)
    MASTER.start()

    while True:
        ZZ = raw_input("running...\ntype 'ZZ' to quit \n\n")
        if 'ZZ' in ZZ:
            print "1. cleaning up... (this can take some time)"
            KILLALL = 1
            sys.exit()
子线程每“x”秒循环并打印一次输出,同时等待键盘输入结束所有操作。 代码永远不会返回到“ZZ”输入,但似乎停留在子线程上:

thread:  1
thread:  2
thread:  3
thread:  4
thread:  5
thread:  6
thread:  7
thread:  ...

我做错了什么?

你应该调用
start()
,而不是
run()
。后者在当前线程而不是新线程的上下文中调用线程func。因此,代码在循环时永远不会到达

您应该调用
start()
,而不是
run()
。后者在当前线程而不是新线程的上下文中调用线程func。因此,代码在
循环时永远不会到达

您应该调用
start()
,而不是
run()
。后者在当前线程而不是新线程的上下文中调用线程func。因此,代码在
循环时永远不会到达

您应该调用
start()
,而不是
run()
。后者在当前线程而不是新线程的上下文中调用线程func。因此,您的代码在
循环时永远不会到达

当您使用'target'参数创建线程对象时,目标应该是一个可调用的对象,它将在新线程启动后在新线程中运行。您在构造函数中调用了QueueMonitor(),因此它在创建线程之前运行。因为您的QueueMonitor永远运行,所以python从未达到创建线程的地步

只需传递函数名即可:

MASTER = threading.Thread(target=QueueMonitor)

当您使用'target'参数创建线程对象时,目标应该是一个可调用的对象,它将在新线程启动后运行。您在构造函数中调用了QueueMonitor(),因此它在创建线程之前运行。因为您的QueueMonitor永远运行,所以python从未达到创建线程的地步

只需传递函数名即可:

MASTER = threading.Thread(target=QueueMonitor)

当您使用'target'参数创建线程对象时,目标应该是一个可调用的对象,它将在新线程启动后运行。您在构造函数中调用了QueueMonitor(),因此它在创建线程之前运行。因为您的QueueMonitor永远运行,所以python从未达到创建线程的地步

只需传递函数名即可:

MASTER = threading.Thread(target=QueueMonitor)

当您使用'target'参数创建线程对象时,目标应该是一个可调用的对象,它将在新线程启动后运行。您在构造函数中调用了QueueMonitor(),因此它在创建线程之前运行。因为您的QueueMonitor永远运行,所以python从未达到创建线程的地步

只需传递函数名即可:

MASTER = threading.Thread(target=QueueMonitor)

很好的编辑调用-一个早期循环的痕迹,但它仍然没有到达while循环-谢谢!很好的编辑调用-一个早期循环的痕迹,但它仍然没有到达while循环-谢谢!很好的编辑调用-一个早期循环的痕迹,但它仍然没有到达while循环-谢谢!很好的编辑调用-一个早期循环的痕迹,但它仍然没有到达while循环-谢谢!target只能是函数的名称。当您说
target=QueueMonitor()
时,QueueMonitor函数实际上就在此时此地运行。请尝试使用
target=QueueMonitor
(不带“()”),就是这样。我想我不能勾选注释以将其标记为解决方案…现在是答案…目标应该是函数的名称。当您说
target=QueueMonitor()
时,QueueMonitor函数实际上就在此时此地运行。请尝试使用
target=QueueMonitor
(不带“()”),就是这样。我想我不能勾选注释以将其标记为解决方案…现在是答案…目标应该是函数的名称。当您说
target=QueueMonitor()
时,QueueMonitor函数实际上就在此时此地运行。请尝试使用
target=QueueMonitor
(不带“()”),就是这样。我想我不能勾选注释以将其标记为解决方案…现在是答案…目标应该是函数的名称。当您说
target=QueueMonitor()
时,QueueMonitor函数实际上就在此时此地运行。请尝试使用
target=QueueMonitor
(不带“()”),就是这样。我想我无法勾选一条评论,将其标记为解决方案…现在是答案。。。