2012-11-12 85 views
0

我如何使用gridfs庫不接受非阻塞gridfs,只有非阻塞其他調用? 我得到錯誤:如何使用gridfs與不接受非阻塞gridfs的庫?

from mongotor.database import Database 
import gridfs 
db = Database.connect("localhost:27017", "mydb") 
fs = gridfs.GridFS(db) 

--------------------------------------------------------------------------- 
TypeError         
Traceback (most recent call last) 
<ipython-input-4-e0f456d7d574> in <module>() 
----> 1 fs = gridfs.GridFS(db) 

C:\Python27\lib\site-packages\pymongo-2.3_-py2.7-win-amd64.egg\gridfs\__init__.pyc in  __init__(self, database, collection) 
49   """ 
50   if not isinstance(database, Database): 
---> 51    raise TypeError("database must be an instance of Database") 
52 
53   self.__database = database 

TypeError: database must be an instance of Database 

做我的理解是GridFS的MUST使用只有阻斷數據庫? (pymongo)

這樣的話,我用pymongo和mongotor,然後我得到:

from mongotor.database import Database 
from pymongo import Connection 
import gridfs 
db = Database.connect("localhost:27017", "mydb") 
dbb = Connection().mydb 
fs = gridfs.GridFS(dbb) 

所以dbb將只在有圖像提供使用?它當然會阻止數據庫調用?所以如果有人正在請求圖片,那麼我的非阻塞呼叫會阻止?

回答

2

的問題是,你混合pymongo和mongotor ...的mongotor的數據庫實現從pymongo的數據庫實現不同的,你不能使用他們一起

MongoTor沒有,還沒有,到GridFS的支持,但是你可以使用電機,異步驅動程序提供的GridFS的,像mongotor:

http://emptysquare.net/motor/pymongo/api/motor/examples/gridfs.html

+0

希望你很快就會實現它:) –