Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created July 18, 2011 04:31

Revisions

  1. James Dennis revised this gist Jul 18, 2011. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,6 @@

    import eventlet
    pymongo = eventlet.import_patched('pymongo')
    from pymongo.errors import AutoReconnect

    ### Setup database connection
    dbc = pymongo.Connection()
  2. James Dennis created this gist Jul 18, 2011.
    24 changes: 24 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/usr/bin/env python

    ###
    ### Concurrent pymongo inserts
    ###

    import eventlet
    pymongo = eventlet.import_patched('pymongo')
    from pymongo.errors import AutoReconnect

    ### Setup database connection
    dbc = pymongo.Connection()
    db = dbc.test

    ### Prepare concurrent resources
    pool = eventlet.GreenPool(1000)

    def do(*args, **kwargs):
    db.test_coll.insert(*args)
    dbc.end_request()

    for i in xrange(1000):
    pool.spawn_n(do, {'num': i})
    pool.waitall()