exxeleron / qPython

interprocess communication between Python and kdb+
http://www.devnet.de
Apache License 2.0
151 stars 90 forks source link

New feature: Connection setup timeout similar to hopen (`:host:port;<timeout>) #49

Closed ktsr42 closed 6 years ago

ktsr42 commented 7 years ago

This pull request adds a connectionTimeout argument to qpython.QConnection. As the name suggests, it specifies a timeout for the initial connection setup. It is designed to mimic the behavior of the timeout argument that q's hopen has, i.e. it defines a maximum wait time for initiating a connection (socket and initial handshake) with a remote q process.

The behavior of the existing timeout parameter is different as it applies to all IO operations over the connection, i.e. the initial connection setup and subsequent queries. In other words, besides limiting the connection setup time, it also limits the maximum duration of queries submitted via qPython to the timeout value. As is, qPtyhon does not offer the ability to change the timeout once it is in place even though the underlying implementation (socket.settimeout()) supports this.

Clients that want to time-box only the connection setup (for example because there are multiple q instances offering the same service, but some of them may be busy servicing other clients) have to accept that the timeout also carries forward to all queries submitted over the connection. Due to the details of the underlying implementation it is not possible to work around the issue by simply ignoring the exception that is thrown should the timeout hit.

The patch enables clients to apply a timeout only to the connection setup phase. It takes care not to change the scope of the existing timeout parameter, that is if both are specified, the timeout parameter takes precedence.

In general, I would question the utility of the original implementation, i.e. mapping the timeout argument to QConnection to socket.settimeout(), for the reason stated above. From my perspective it would be more consistent to follow q's behavior and have a connection setup timeout, but no outgoing query timeout.

SKolodynski commented 6 years ago

The project is in maintenance mode now. We will not add any new features in foreseeable future.