python win32api阻塞瓶路线 [英] python win32api blocking bottle routes

查看:139
本文介绍了python win32api阻塞瓶路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Bottle Web应用程序。在某个时候,我希望服务器引发一个对话框,要求服务器管理员提供某些信息。即使从 Thread 启动,此警报也会阻止-我真的不明白为什么。

I have a bottle web application. At some point, i want the server to raise a dialog window to ask the server admin for something. This alert, even when started from a Thread is blocking - And i don't really understand why.

要查看此ctypes MessageBox是否被阻止,我尝试在一个最小的示例上在线程上运行它。我已经尝试过以下示例:

To see if this ctypes MessageBox is blocking, i've tried to run it on a thread on a minimal example. I've tried this example:

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秒显示一次从线程启动的警报方法。我们清楚地看到,循环不是在等待对话框返回值。

Here, the main thread keeps on printing on 2 seconds interval. Concurrently, each 3 seconds the alert method started from a thread is shown. We clearly see that the loop isn't waiting for the dialog to return a value.

尽管从瓶子应用程序尝试类似代码时,此测试一直到是。或在对话框上单击否,则服务器不响应其路由。而是等待对话框返回一个值,这意味着该对话框在某种程度上阻止了执行。

Despite this test, when trying similar code from a bottle application, until 'Yes' or 'No' is clicked on the dialog, the server does not respond to it's routes. Instead, it waits for the dialog to return a value, which means the dialog is blocking execution at some level.

任何人都知道如何在不影响瓶装工作的情况下引发对话框。 ?我的想法不多了。感谢您的时间和精力。

Anyone knows how to raise a dialog without interfering with bottle work? I'm running out of ideas. Appreciate your time and effort.



更新:

这不是问题。瓶子确实在没有干扰的情况下运行。在这里可以更好地描述实际问题: bottle gevent和线程:gevent仅可用于单个线程

推荐答案

您可能会在您的Bottle应用程序中使用Gevent 。如果您选择monkey.patch_all(),则您的线程将变为串行线程,并会阻止执行瓶。

You probably use Gevent with your bottle application . If you monkey.patch_all() , your threads become serial , and will block bottle execution .

您不应该修补线程:

from gevent import monkey
monkey.patch_all(thread=False)

这篇关于python win32api阻塞瓶路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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