A reactor which make twisted compatc with gevent
Originally I wrote code for Scrapy. I want to combine gevent in Scrapy, so I created this greenreactor.
pip install greenreactor
# Usually we need monkey patch, simply patch all things or patch part of them if you understand what you are doing.
# Guideline: http://www.gevent.org/api/gevent.monkey.html
import gevent.monkey
# Disable some patch properly, for example: DISABLE THREAD PATCH ---- gevent.monkey.patch_all(thread=False)
gevent.monkey.patch_all()
# Install greenreactor
import greenreactor
greenreactor.install()
from twisted.internet import reactor
reactor.run()
Thats all! Now you can use any gevent api such as spawn
, spawn_later
, etc.