Created
November 7, 2012 21:01
-
-
Save cyounkins/4034431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.