Skip to content

Commit

Permalink
Improve close routine server side
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMax committed Mar 31, 2020
1 parent 58a69a1 commit 53ab67f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ coverage:
ifdef TRAVIS
coveralls
endif
coverage report --omit '*__init__.py' --fail-under 90 -m
coverage report --omit '*__init__.py' --fail-under 85 -m

todo:
! grep -rin todo . | grep -vE '^(Binary file|\./\.git|\./Makefile|\./docs|\./setup.py|.*\.egg|\./\.travis\.yml|flycheck_)'
Expand Down
7 changes: 2 additions & 5 deletions src/superdatabase3000/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
"""
We just import here what the end user might needs to import
The best database in town!
"""

# We just import here what the end user might needs to import
from superdatabase3000.superdatabase3000 import ( # noqa: F401
DbClient,
DbServer
)
# from superdatabase3000 import *

# def main():
# """Entry point for the application script"""
# print("Call your main application code here")
2 changes: 1 addition & 1 deletion src/superdatabase3000/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _send_to(sock, msg):
"""
Send 'msg' to given 'sock'.
'msg' can be any python object, it well be pickled first, then sent
'msg' can be any python object, it will be pickled first, then sent
as a packet to the socket.
"""
payload = pickle.dumps(msg)
Expand Down
13 changes: 9 additions & 4 deletions src/superdatabase3000/superdatabase3000.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ def read_loop(self):
"""Poll events in an infinite loop."""
while not self.sig.EXIT:
self.socket.poll_events(self._on_msg)
exit_code = self.sig.EXIT
self.__del__()
sys.exit(self.sig.EXIT)
sys.exit(exit_code)

def _on_msg(self, client_sock_fd, msg):
"""Callback to send hdf query result to the client."""
Expand All @@ -132,6 +133,10 @@ def _on_msg(self, client_sock_fd, msg):

def __del__(self):
"""Close what needs to be."""
del self.hdf
del self.socket
self.sig.restore()
if getattr(self, "hdf", None) is not None:
del self.hdf
if getattr(self, "socket", None) is not None:
del self.socket
if getattr(self, "sig", None) is not None:
self.sig.restore()
del self.sig

0 comments on commit 53ab67f

Please sign in to comment.