The current timing of transport creation is inside connection._init_. It's OK in all scenarios in one process model.
But if users need to run Gremlin Python SDK inside services like `celery` which use multiple processes model, this implementation may cause error.
As transport(which represents socket) is created inside Main Processes, it will be inherited by Child Processes, then threads inside ThreadPoolExecutor will try to read from the same socket, so it may happen that:
- Child Process 1 send a request with request id 'xxx' use socket s1
- Child Process 2 send another request with request id 'yyy' also use socket s1, then able to read the response of request id 'xxx', but unable to find 'xxx' inside '_results'
If this happens, it will cause KeyError exception like:
Steps to reproduce:
- Following the [tutorial|https://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html] of Celery to create a simple app named `tasks`
- Refactor `tasks.py` to send request through Gremin Python SDK inside the task method
- Invoke `add.delay(1,2)`
There is a quick fix which changes several lines inside `connection.py` without breaking other code: