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
粉碎机和数据库连接
原标题:Python Twisted and database connections
问题回答
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,返回被推迟者,但涉及的是更多相同的密码途径。
我所看到的所有数据库图书馆似乎都很麻烦。
看来,Twisted. Enterprises.abapi通过利用透镜来管理连接库和总结基础数据库图书馆来解决这一问题。 这显然不理想,但我相信,这将奏效,但我实际上没有尝试过。
理想的情况是,将chem化和tw化混为一谈。 我发现这个项目,nadbapi,声称是这样做的,但自2007年以来,它看一看它没有更新过。
相关问题
热门标签
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding