Skip to content

Commit

Permalink
Merge pull request #37 from maciejlach/master
Browse files Browse the repository at this point in the history
Fix: QConnection.close() frees linked file object
  • Loading branch information
rafalsytek committed Apr 1, 2016
2 parents b69d507 + ecd6bd0 commit 62ddd7d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
------------------------------------------------------------------------------
qPython 1.2.1 [2016.03.29]
------------------------------------------------------------------------------

- Fix: QConnection.close() frees linked file object

------------------------------------------------------------------------------
qPython 1.2.0 [2016.01.22]
------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion qpython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
__all__ = ['qconnection', 'qtype', 'qtemporal', 'qcollection']


__version__ = '1.2.0'
__version__ = '1.2.1'



Expand Down
7 changes: 6 additions & 1 deletion qpython/qconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(self, host, port, username = None, password = None, timeout = None,
self.password = password

self._connection = None
self._connection_file = None
self._protocol_version = None

self.timeout = timeout
Expand Down Expand Up @@ -143,7 +144,7 @@ def open(self):
self._initialize()

self._writer = self._writer_class(self._connection, protocol_version = self._protocol_version, encoding = self._encoding)
self._reader = self._reader_class(self._connection.makefile('b'), encoding = self._encoding)
self._reader = self._reader_class(self._connection_file, encoding = self._encoding)


def _init_socket(self):
Expand All @@ -152,14 +153,18 @@ def _init_socket(self):
self._connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._connection.connect((self.host, self.port))
self._connection.settimeout(self.timeout)
self._connection_file = self._connection.makefile('b')
except:
self._connection = None
self._connection_file = None
raise


def close(self):
'''Closes connection with the q service.'''
if self._connection:
self._connection_file.close()
self._connection_file = None
self._connection.close()
self._connection = None

Expand Down

0 comments on commit 62ddd7d

Please sign in to comment.