Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created July 18, 2011 04:31
Show Gist options
  • Save j2labs/1088546 to your computer and use it in GitHub Desktop.
Save j2labs/1088546 to your computer and use it in GitHub Desktop.
Concurrent pymongo inserts with Eventlet
#!/usr/bin/env python
###
### Concurrent pymongo inserts
###
import eventlet
pymongo = eventlet.import_patched('pymongo')
### 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()
@coltenkrauter
Copy link

What version of pymongo is imported here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment