Skip to content

Instantly share code, notes, and snippets.

@liushuaikobe
Forked from cyounkins/gist:4034431
Created October 21, 2013 08:36
Show Gist options
  • Save liushuaikobe/7080523 to your computer and use it in GitHub Desktop.
Save liushuaikobe/7080523 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment