尝试使用之后,我每次15秒都要求锤击服务器 请求数据自上次以来,HTTP HEAD指令检查数据是否已更改 。 I am a complete ignoramus and newbie when it comes to designing andcoding networked clients (or servers for that matter). I have a copyof Goerzen (Foundations of Python Network Programming) and oncepointed in the best direction should be able to follow my nose and getthings sorted... but I am not quite sure which is the best path totake and would be grateful for advice from networking gurus.I am writing a program to display horse racing tote odds in a desktopclient program. I have access to an HTTP (open one of several URLs,and I get back an XML doc with some data... not XML-RPC.) source ofXML data which I am able to parse and munge with no difficulty at all.I have written and successfully tested a simple command line programwhich allows me to repeatedly poll the server and parse the XML. Easyenough, but the real world production complications are:1) The data for the race about to start updates every (say) 15seconds, and the data for earlier and later races updates only every(say) 5 minutes. There is no point for me to be hammering the serverwith requests every 15 seconds for data for races after the upcomingrace... I should query for this perhaps every 150s to be safe. But forthe upcoming race, I must not miss any updates and should query every~7s to be safe. So... in the middle of a race meeting the situationmight be:race 1 (race done with, no-longer querying), race 2 (race done with,no longer querying) race 3 (about to start, data on server for thisrace updating every 15s, my client querying every 7s), races 4-8 (dataon server for these races updating every 5 mins, my client queryingevery 2.5 mins)2) After a race has started and betting is cut off and there areconsequently no more tote updates for that race (it is possible todetermine when this occurs precisely because of an attribute in theXML data), I need to stop querying (say) race 3 every 7s and removerace 4 from the 150s query group and begin querying its data every 7s.3) I need to dump this data (for all races, not just current about tostart race) to text files, store it as BLOBs in a DB *and* update realtime display in a wxpython windowed client.My initial thought was to have two threads for the different updatepolling cycles. In addition I would probably need another thread tohandle UI stuff, and perhaps another for dealing with file/DB datawrite out. But, I wonder if using Twisted is a better idea? I willstill need to handle some threading myself, but (I think) only forkeeping wxpython happy by doing all this other stuff off the mainthread + perhaps also persisting received data in yet another thread.I have zero experience with these kinds of design choices and would bevery happy if those with experience could point out the pros and consof each (synchronous/multithreaded, or Twisted) for dealing with thetwo differing sample rates problem outlined above.Many TIA! 解决方案IMHO using twisted will give you the best performance and framework. Since ituses callbacks for every request, your machine could handle a LOT of differentexternal queries and keep everything updated in WX. Might be a little tricky toget working with WX, but I recall Googling for something like this not long agoand there appeared to be sufficient information on how to get working. http://twistedmatrix.com/projects/co...g-reactor.htmlTwisted even automatically uses threads to keep SQL database storage routinesfrom blocking (see Chapter 4 of Twisted Network Programming Essentials)This is an ambitious project, good luck.-LarryTry using an HTTP HEAD instruction instead to check if the data haschanged since last time. 这篇关于设计选择:多线程/异步wxpython客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!