pyro: Return new proxy instances if called from outside of a request context.

This allows to run code that uses the pyro connection to the VCSServer
but does not execute from within a request context, e.g. invoke tasks.
This commit is contained in:
Martin Bornhold 2016-07-05 09:37:13 +02:00
parent d29f7ba684
commit 64893dfad5

View file

@ -214,7 +214,16 @@ class RequestScopeProxyFactory(object):
"""
Call this to get the pyro proxy instance for the request.
"""
# Return already borrowed proxy for this request
# If called without a request context we return new proxy instances
# on every call. This allows to run e.g. invoke tasks.
if request is None:
log.info('Creating pyro proxy without request context for '
'remote_uri=%s', self._remote_uri)
return Pyro4.Proxy(self._remote_uri)
# If there is an already borrowed proxy for the request context we
# return that instance instead of creating a new one.
if request in self._borrowed_proxies:
return self._borrowed_proxies[request]