replaced locking with gevent.BoundedSemaphore