Code Monkey home page Code Monkey logo

Comments (11)

fiorix avatar fiorix commented on July 23, 2024

You're right. There's something funky going on with get and put. Whoever implemented it missed handling callbacks properly. Patches are welcome.

Good news is that there are other ways of getting it to work, like this:

from twisted.internet import defer                                                              
from twisted.internet import reactor                                         

import txmongo                                                               
from txmongo.gridfs import GridFS                                            


@defer.inlineCallbacks                                                       
def main():                                                                  
    mongo = yield txmongo.MongoConnectionPool()                              
    db = mongo.test                                                          

    gfs = GridFS(db, "fs")                                                   
    ifp = gfs.new_file(filename="foobar.txt", content_type="text/plain")     
    yield ifp.write("just another victim")                                   
    yield ifp.close()                                                        

    ofp = yield gfs.get_last_version("foobar.txt")                           
    contents = yield ofp.read()                                              

    print "filename=%s\ncontent_type=%s\nlength=%s\ncontents=%s" % \         
            (ofp.filename, ofp.content_type, ofp.length, contents)           


if __name__ == "__main__":                                                   
    main().addCallback(lambda ign: reactor.stop())                           
    reactor.run()                                                            

It gives me this:

$ mongofiles list                                                            
connected to: 127.0.0.1                                                      

$ python test.py                                                             
filename=foobar.txt                                                          
content_type=text/plain                                                      
length=19                                                                    
contents=just another victim                                                 

$ mongofiles list                                                            
connected to: 127.0.0.1                                                      
foobar.txt  19                                                               

$ mongofiles delete foobar.txt                                               
connected to: 127.0.0.1                                                      
done!                                                                        

This whole thing needs an update. I haven't been using mongo for a while, thus, not working on this as well.

from txmongo.

gleicon avatar gleicon commented on July 23, 2024

Me too, long time not using mongodb. Any pointers on what to look for ? I can give it a try later.

from txmongo.

fiorix avatar fiorix commented on July 23, 2024

The code is actually simple, but it's kinda messed up. There are read/write/close calls not handling the deferreds returned by them. It seems to be copied from pymongo, as opposed to properly "ported" to twisted.

from txmongo.

iffy avatar iffy commented on July 23, 2024

I'm happy to submit a patch. I also noticed that it was just copied
from pymongo... and thought that was dumb :). So, the goal is to have
Deferred-returning methods? I'm just experimenting with mongodb to
see if we'll use it -- not sure yet, but maybe I'll submit a patch so
that the next person who wants to play with it has a better
experience.

On Mon, Jun 25, 2012 at 1:16 PM, Alexandre Fiori
[email protected]
wrote:

The code is actually simple, but it's kinda messed up. There are read/write/close calls not handling the deferreds returned by them. It seems to be copied from pymongo, as opposed to properly "ported" to twisted.


Reply to this email directly or view it on GitHub:
#40 (comment)

from txmongo.

fiorix avatar fiorix commented on July 23, 2024

The above code should help. At the end of the day, using it should be like objid = yield gfs.put(...) and fileobj = yield gfs.get(objid).

Also, I noticed GridOut (returned by get) treats that objid as a dict, when it's actually either an instance of ObjectId or a plain string. Not sure what's missing in there.

from txmongo.

fiorix avatar fiorix commented on July 23, 2024

Last time I used mongo was version 1.4, and I had a pretty bad experience on high load. Since then, I've been using redis with mysql and/or pgsql on almost every project.

from txmongo.

dynamicgl avatar dynamicgl commented on July 23, 2024

now there is mongodb 2.x, performance has been improved a lot.

from txmongo.

psi29a avatar psi29a commented on July 23, 2024

@iffy You still interested in making that patch? :)

from txmongo.

iffy avatar iffy commented on July 23, 2024

@psi29a Probably not :( We ended up not using Mongo, so it would be far afield of what I'm doing now.

from txmongo.

IlyaSkriblovsky avatar IlyaSkriblovsky commented on July 23, 2024

GridFS.put() seems to be working now. May we close this issue?

from txmongo.

psi29a avatar psi29a commented on July 23, 2024

I think we can close this, if someone tests and isn't happy... they can post here and we can re-open it.

from txmongo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.