Skip to content

Instantly share code, notes, and snippets.

@cyounkins
Created November 7, 2012 21:01
Show Gist options
  • Save cyounkins/4034431 to your computer and use it in GitHub Desktop.
Save cyounkins/4034431 to your computer and use it in GitHub Desktop.
import gevent.monkey
gevent.monkey.patch_all()
import time
import pymongo
connection = pymongo.Connection(use_greenlets=True)
def task():
collection = connection.autoref.all_cars
# Make cursor, and make sure it opens a socket
cursor = collection.find()
cursor.next()
# Supposedly return this socket to the pool
connection.end_request()
if __name__ == "__main__":
jobs = [gevent.spawn(task) for i in xrange(500)]
gevent.joinall(jobs)
@liushuaikobe
Copy link

I have read your discussion in Google online forum. Is this the correct usage of gevent with pymongo?
Or, Hopefully, I'm new to pymongo, do you have any other examples of the gevent with pymongo?
Thanks.

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