gmr / rabbitpy

A pure python, thread-safe, minimalistic and pythonic RabbitMQ client library
http://rabbitpy.readthedocs.org
BSD 3-Clause "New" or "Revised" License
243 stars 58 forks source link

Don't spin while waiting for the socket to connect. #26

Closed kristaps closed 10 years ago

kristaps commented 10 years ago

Spinning prevents rabbitpy from working with code that uses gevent and its monkey patch. For example "Connected" wouldn't get printed in the following example as the IO thread will be starved by the main thread spinning in Connection._connect():

from gevent import monkey; monkey.patch_all()
import rabbitpy

connection = rabbitpy.Connection('amqp://guest:guest@localhost/%2F?locale=en_US.UTF-8')
print "Connected"
connection.close()

Waiting on an event gives other greenlets a chance to run and the IO thread can complete the connection.

gmr commented 10 years ago

Looks good, thanks!