蟒蛇win32api阻止瓶路线
问题描述:
我有一个瓶子的web应用程序。在某些时候,我希望服务器提出一个对话窗口来询问服务器管理员的某些事情。即使从Thread
开始,此警报也被阻止 - 我不明白为什么。蟒蛇win32api阻止瓶路线
若要查看此ctypes MessageBox是否阻塞,我试图在一个最小示例上的线程上运行它。我试过这个例子:
import threading
from threading import Thread
import ctypes
import time
MessageBox = ctypes.windll.user32.MessageBoxA
def alert():
userChoice = MessageBox(0, "And this is crazy", "Hey I just met you",4)
threading.Timer(3.0,alert).start()
worker = Thread(target=alert)
worker.setDaemon(False)
worker.start()
while (True):
print("main thread is printing")
time.sleep(2)
在这里,主线程持续打印2秒间隔。同时,每3秒钟显示从线程开始的警报方法。我们清楚地看到循环不等待对话框返回值。
尽管进行了此测试,但在尝试类似瓶子应用程序的代码时,直到在对话框中单击“是”或“否”,服务器才会响应其路由。相反,它会等待对话框返回一个值,这意味着对话框会在某个级别阻止执行。
任何人都知道如何在不干扰瓶子工作的情况下举办对话?我正在用尽想法。感谢您的时间和精力。
UPDATE:
这是没有问题的。瓶子在没有干扰的情况下运行。实际问题在这里描述得更好:bottle gevent and threading: gevent is only usable from a single thread
答
您可能在您的瓶子应用程序中使用Gevent。如果您使用monkey.patch_all(),您的线程将变为串行,并将阻止瓶子执行。
你不应该修补的线程:
from gevent import monkey
monkey.patch_all(thread=False)
这就提出了另一个问题,http://stackoverflow.com/questions/16517796/bottle-gevent-and-threading-gevent-is-only-usable-从-A-单线程 – user1555863 2013-05-13 08:37:53