Skip to content

Commit

Permalink
pyDKB/cds: add custom signal handlers for SIGINT and SIGTERM
Browse files Browse the repository at this point in the history
Another try to deal with Issue #45; doesn`t seem to work, though.
  • Loading branch information
mgolosova committed Oct 28, 2017
1 parent 55fd556 commit 58321db
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Utils/Dataflow/pyDKB/dataflow/cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import sys
import signal
import os

try:
import kerberos
Expand All @@ -22,6 +23,19 @@

class CDSInvenioConnector(cds.CDSInvenioConnector):
""" CDSInvenioConnector which closes the browser in most cases. """

orig_handlers = {}
handlers = False

def __init__(self, *args):
self.orig_handlers = {
signal.SIGINT: signal.signal(signal.SIGINT, self.kill),
signal.SIGTERM: signal.signal(signal.SIGTERM, self.kill)
}
handlers = True
super(CDSInvenioConnector, self).__init__(*args)


def __enter__(self):
""" Enter the with...as construction. """
return self
Expand All @@ -34,13 +48,24 @@ def __exit__(self, exc_type, exc_val, exc_tb):
return True

def __del__(self):
self.delete()
self.delete(False)

def delete(self):
def delete(self, restore_handlers=True):
if getattr(self, 'browser', None):
self.browser.driver.service.process.send_signal(signal.SIGTERM)
self.browser.quit()
del self.browser
if restore_handlers:
for s in self.orig_handlers:
signal.signal(s, self.orig_handlers[s])


def kill(self, signum, frame):
""" Run del and propagate signal. """
self.delete()
os.kill(os.getpid(), signum)



class KerberizedCDSInvenioConnector(CDSInvenioConnector):
"""
Expand Down

0 comments on commit 58321db

Please sign in to comment.