def protocol_factory(): return protocol.GremlinServerWSProtocol( self._message_serializer, username=self._username, password=self._password, kerberized_service=kerberized_service, max_content_length=transport_kwargs["max_content_length"])
def __init__(self, url, traversal_source, protocol_factory=None, transport_factory=None, pool_size=None, max_workers=None, message_serializer=None, username="", password="", kerberized_service="", headers=None, session=""): self._url = url self._headers = headers self._traversal_source = traversal_source if message_serializer is None: message_serializer = serializer.GraphSONSerializersV3d0() self._message_serializer = message_serializer self._username = username self._password = password self._session = session self._sessionEnabled = (session != "") if transport_factory is None: try: from gremlin_python.driver.tornado.transport import ( TornadoTransport) except ImportError: raise Exception("Please install Tornado or pass" "custom transport factory") else: transport_factory = lambda: TornadoTransport() self._transport_factory = transport_factory if protocol_factory is None: protocol_factory = lambda: protocol.GremlinServerWSProtocol( self._message_serializer, username=self._username, password=self._password, kerberized_service=kerberized_service) self._protocol_factory = protocol_factory if self._sessionEnabled: if pool_size is None: pool_size = 1 elif pool_size != 1: raise Exception("PoolSize must be 1 on session mode!") if pool_size is None: pool_size = 4 self._pool_size = pool_size # This is until concurrent.futures backport 3.1.0 release if max_workers is None: # If your application is overlapping Gremlin I/O on multiple threads # consider passing kwarg max_workers = (cpu_count() or 1) * 5 max_workers = pool_size self._executor = ThreadPoolExecutor(max_workers=max_workers) # Threadsafe queue self._pool = queue.Queue() self._fill_pool()
def __init__(self, url, traversal_source, protocol_factory=None, transport_factory=None, pool_size=None, max_workers=None, message_serializer=None, username="", password="", headers=None, ping_interval=None): self._url = url self._headers = headers self._traversal_source = traversal_source if message_serializer is None: message_serializer = serializer.GraphSONSerializersV3d0() self._message_serializer = message_serializer self._username = username self._password = password self._ping_interval = ping_interval if transport_factory is None: try: from gremlin_python.driver.tornado.transport import ( TornadoTransport) except ImportError: raise Exception("Please install Tornado or pass" "custom transport factory") else: transport_factory = lambda: TornadoTransport() self._transport_factory = transport_factory if protocol_factory is None: protocol_factory = lambda: protocol.GremlinServerWSProtocol( self._message_serializer, username=self._username, password=self._password) self._protocol_factory = protocol_factory if pool_size is None: pool_size = 4 self._pool_size = pool_size # This is until concurrent.futures backport 3.1.0 release if max_workers is None: # Use this number because ThreadPoolExecutor is often # used to overlap I/O instead of CPU work. max_workers = (cpu_count() or 1) * 5 self._executor = ThreadPoolExecutor(max_workers=max_workers) # Threadsafe queue self._pool = queue.Queue() self._fill_pool() if (ping_interval): self._ping_event_loop = asyncio.new_event_loop() self._ping_thread = Thread(target=self.ping_server, args=(self._ping_event_loop, ), daemon=True) self._ping_thread.start()
def protocol_factory(): return protocol.GremlinServerWSProtocol( self._message_serializer, username=self._username, password=self._password, kerberized_service=kerberized_service) self._protocol_factory = protocol_factory