English 中文(简体)
粉碎机和数据库连接
原标题:Python Twisted and database connections
  • 时间:2009-11-10 03:20:59
  •  标签:

Our projects at work include synchronous applications (short lived) and asynchronous Twisted applications (long lived). We re re-factoring our database and are going to build an API module to decouple all of the SQL in that module. I d like to create that API so both synchronous and asynchronous applications can use it. For the synchronous applications I d like calls to the database API to just return data (blocking) just like using MySQLdb, but for the asynchronous applications I d like calls to the same API functions/methods to be non-blocking, probably returning a deferred. Anyone have any hints, suggestions or help they might offer me to do this? Thanks in advance, Doug

问题回答

rel=“nofollow noreferer”>twisted.business.adbapi 看上去看,你是否认为这不符合你的要求,如果是,请解释为什么?

在Twisted,你基本希望有一个包裹,以恢复被推迟(例如,Twisted DB层)的职能,等待结果,并返回。 然而,你可能会忙.,因为你利用反应堆循环,检查完成使用无锁等候的任务,可能效率低下。

是否有退步或推迟的召集人解决你的问题? 它们需要现代化的Twisted. 。 See the twistedmatrix docs.

def thingummy():
   thing = yield makeSomeRequestResultingInDeferred()
   print thing #the result! hoorj!
thingummy = inlineCallbacks(thingummy)

另一种选择是,采用两种方法,使用run Interaction,其中区块和使用Query,返回被推迟者,但涉及的是更多相同的密码途径。





相关问题
热门标签