开发者

Merging two event loops (Cherrypy and Wxpython)

Okay, I have an application written with cherrypy, and I want to build a wxpython gui for it. The problem is that both modules use a close loop for event handling, which (I assume) means while one is running the other will be locked.

I asked for some advice and it was suggested that I merge the two event loops rather than using the stock entrypoints (quickloop() for cherrypy and MainLoop() for wx)

The problem is I have no idea how to do this. Any advice would be greatly appreciat开发者_StackOverflow社区ed.


You already asked the same question here: cherrypy and wxpython, and I gave you the best response you're going to find anywhere there, which was voted up and you approved, apparently. Why are you asking again?


In the case of cherrypy, you have the source. Look in the code what quickloop() does and then try to merge this code with the MainLoop() of WX.

Both loops will probably look like this:

while (true) {
    if (pendingEvents()) processEvents ();
    else waitForEvents ();
}

You must find a way to merge the two waiting calls into one (so the code continues if either event source had pending events). For WX, look at Dispatch(), Pending() and ProcessIdle().

Or you can look at wxIdleEvent (see the docs) and process all cherrypy events in there.

Another solution might be to run the two loops in different threads. In this case, you can't call WX methods from cherrypy code and vice versa. To solve this, you must find a way to send messages to the other thread with all the information which method to call. This makes sure that WX methods get executed in the WX thread and cherrypy methods get executed in the cherrypy thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜