[ 
https://issues.apache.org/jira/browse/TINKERPOP-2752?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17556516#comment-17556516
 ] 

Stephen Mallette commented on TINKERPOP-2752:
---------------------------------------------

We added {{transport_factory}} so that folks could plug-in their own 
implementations. If that is working for you, then I'm glad it is solving your 
problems. While I appreciate your offer to contribute another implementation 
I'm sorry to say that I don't think it's something I'd be in favor of. I'd 
prefer we just have one reference implementation to maintain. I'm not sure if 
anyone else feels differently but that's my position at least. 

> `AiohttpTransport` malfunctions in an eventlet monkey patched app
> -----------------------------------------------------------------
>
>                 Key: TINKERPOP-2752
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2752
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: python
>    Affects Versions: 3.6.0, 3.5.2
>         Environment: python 3.8, running both natively on macOS, and within a 
> Docker container hosted on macOS
>            Reporter: Steve Kieffer
>            Priority: Blocker
>
> I'm running an eventlet-based Flask web app, that starts out with a call to
> {code:python}
> eventlet.monkey_patch()
> {code}
> and has view functions that use gremlin-python to connect to a gremlin server.
> I've found that if the browser issues several requests in rapid succession, 
> it can provoke the
> {code:python}
> RuntimeError: Cannot run the event loop while another loop is running
> {code}
> error. Passing
> {code:python}
> call_from_event_loop=True
> {code}
> when constructing the {{DriverRemoteConnection}} just leads to a different 
> type of error, because the problem is transient, not consistent.
> I've developed a minimal example that demonstrates the issue, and can share a 
> link to that if it would be helpful.
> *Possible solution:*
> How about supplying another transport, besides the {{AiohttpTransport}} 
> class, which uses the {{websocket-client}} python package, instead of 
> {{aiohttp}}?
> I've made one which is very rudimentary but, in testing so far, works fine 
> and solves this issue:
> {code:python}
> from gremlin_python.driver.transport import AbstractBaseTransport
> import websocket
> class WebsocketTransport(AbstractBaseTransport):
>     def __init__(self, **kwargs):
>         self.ws = websocket.WebSocket(**kwargs)
>     def connect(self, url, headers=None):
>         headers = headers or []
>         self.ws.connect(url, header=headers)
>     def write(self, message):
>         self.ws.send_binary(message)
>     def read(self):
>         return self.ws.recv()
>     def close(self):
>         self.ws.close()
>     @property
>     def closed(self):
>         return not self.ws.connected
> def transport_factory():
>     return WebsocketTransport()
> {code}
> Happy to open this as a PR, if it seems like a good idea.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to