twistedutil.SimpleSpawnFactory: deliver exceptions to the handler if it does support it
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
|
|
||||||
"""Basic twisted protocols converted to synchronous mode"""
|
"""Basic twisted protocols converted to synchronous mode"""
|
||||||
|
import sys
|
||||||
from twisted.internet.protocol import Protocol as twistedProtocol
|
from twisted.internet.protocol import Protocol as twistedProtocol
|
||||||
from twisted.internet.error import ConnectionDone
|
from twisted.internet.error import ConnectionDone
|
||||||
from twisted.internet.protocol import Factory, ClientFactory
|
from twisted.internet.protocol import Factory, ClientFactory
|
||||||
@@ -384,7 +385,12 @@ class SimpleSpawnFactory(Factory):
|
|||||||
gtransport_class = GreenTransport
|
gtransport_class = GreenTransport
|
||||||
|
|
||||||
def __init__(self, handler, gtransport_class=None, *args, **kwargs):
|
def __init__(self, handler, gtransport_class=None, *args, **kwargs):
|
||||||
|
if callable(handler):
|
||||||
self.handler = handler
|
self.handler = handler
|
||||||
|
else:
|
||||||
|
self.handler = handler.send
|
||||||
|
if hasattr(handler, 'send_exception'):
|
||||||
|
self.exc_handler = handler.send_exception
|
||||||
if gtransport_class is not None:
|
if gtransport_class is not None:
|
||||||
self.gtransport_class = gtransport_class
|
self.gtransport_class = gtransport_class
|
||||||
self.args = args
|
self.args = args
|
||||||
@@ -401,7 +407,11 @@ class SimpleSpawnFactory(Factory):
|
|||||||
proc.spawn_greenlet(self._run_handler, gtransport, protocol)
|
proc.spawn_greenlet(self._run_handler, gtransport, protocol)
|
||||||
|
|
||||||
def _run_handler(self, gtransport, protocol):
|
def _run_handler(self, gtransport, protocol):
|
||||||
|
try:
|
||||||
gtransport._init_transport()
|
gtransport._init_transport()
|
||||||
|
except Exception:
|
||||||
|
self.exc_handler(*sys.exc_info())
|
||||||
|
else:
|
||||||
self.handler(gtransport)
|
self.handler(gtransport)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user