def ungreen_psycopg(): """Temporarily disable gevent support in psycopg. Inside this context manager you can use psycopg's features that are not compatible with coroutine support, such as large objects. Of course, at the expense of being blocking, so please stay inside the context manager as short as possible. """ is_green = is_psycopg_green() if is_green: unmake_psycopg_green() try: yield finally: if is_green: make_psycopg_green()
import gevent.event from gevent.server import StreamServer from cmscommon.DateTime import monotonic_time from cms.io import ServiceCoord, Address, get_service_address from cms.io.Utils import random_string, Logger, \ encode_json, decode_json from cms.io.PsycoGevent import make_psycopg_green # Our logger object - can be a standard one (provided in Utils), or a # custom one provided by the class subclassing service. logger = None # Fix psycopg in order to support gevent greenlets make_psycopg_green() def rpc_callback(func): """Tentative decorator for a RPC callback function. Up to now it does not do a lot, I hope to be able to manage errors in a Pythonic way. """ @wraps(func) def newfunc(self, *args, **kwargs): """Mangle __error and give back error when appropriate. """ if "__error" in kwargs: if kwargs["__error"] is not None:
from gevent.server import StreamServer from gevent.backdoor import BackdoorServer # We import the module, instead of its contents (i.e. "from cms.log # import ..."), to avoid a circular import. import cms.log from cms import config, mkdir from cms.io import ServiceCoord, Address, get_service_address from cms.io.Utils import encode_json, decode_json from cms.io.PsycoGevent import make_psycopg_green from cmscommon.DateTime import monotonic_time logger = logging.getLogger(__name__) # Fix psycopg in order to support gevent greenlets make_psycopg_green() def rpc_callback(func): """Tentative decorator for a RPC callback function. Up to now it does not do a lot, I hope to be able to manage errors in a Pythonic way. """ @wraps(func) def newfunc(self, *args, **kwargs): """Mangle __error and give back error when appropriate. """ if "__error" in kwargs: if kwargs["__error"] is not None: