Skip to content

Commit

Permalink
use finishedFlag to signal processTape has finished, removed Keyboard…
Browse files Browse the repository at this point in the history
…Interrupt
  • Loading branch information
bitsgalore committed Dec 4, 2018
1 parent 2709490 commit 752db32
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
32 changes: 16 additions & 16 deletions tapeimgr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,22 +195,22 @@ def main():
# Start main processing function
try:
myCLI.process()
except KeyboardInterrupt:
if myCLI.tape.tapeDeviceIOError:
# Tape device not accessible
msg = ('Cannot access tape device ' + myCLI.tape.tapeDevice +
'. Check that device exists, and that tapeimgr is run as root')
errorExit(msg)
elif myCLI.tape.successFlag:
# Tape extraction completed with no errors
msg = ('Tape processed successfully without errors!')
printInfo(msg)
sys.exit(0)
else:
# Tape extraction resulted in errors
msg = ('One or more errors occurred while processing tape, '
'check log file for details')
errorExit(msg)
if myCLI.tape.finishedFlag:
if myCLI.tape.tapeDeviceIOError:
# Tape device not accessible
msg = ('Cannot access tape device ' + myCLI.tape.tapeDevice +
'. Check that device exists, and that tapeimgr is run as root')
errorExit(msg)
elif myCLI.tape.successFlag:
# Tape extraction completed with no errors
msg = ('Tape processed successfully without errors!')
printInfo(msg)
sys.exit(0)
else:
# Tape extraction resulted in errors
msg = ('One or more errors occurred while processing tape, '
'check log file for details')
errorExit(msg)
except Exception as e:
# Unexpected error
msg = 'An unexpected error occurred, see log file for details'
Expand Down
46 changes: 25 additions & 21 deletions tapeimgr/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, parent, *args, **kwargs):
self.queue_handler = QueueHandler(self.log_queue)
# Create tape instance
self.tape = Tape()
self.t1 = None
# Read configuration file
self.tape.getConfiguration()
# Build the GUI
Expand Down Expand Up @@ -119,8 +120,9 @@ def on_submit(self):
self.quit_button.config(state='disabled')

# Launch tape processing function as subprocess
t1 = threading.Thread(target=self.tape.processTape)
t1.start()
self.t1 = threading.Thread(target=self.tape.processTape)
self.t1.start()


def selectOutputDirectory(self, event=None):
"""Select output directory"""
Expand Down Expand Up @@ -339,25 +341,27 @@ def main():
root.update_idletasks()
root.update()
time.sleep(0.1)
except KeyboardInterrupt:
if myGUI.tape.tapeDeviceIOError:
# Tape device not accessible
msg = ('Cannot access tape device ' + myGUI.tape.tapeDevice +
'. Check that device exits, and that tapeimgr is run as root')
errorExit(msg)
elif myGUI.tape.successFlag:
# Tape extraction completed with no errors
msg = ('Tape processed successfully without errors')
tkMessageBox.showinfo("Success", msg)
else:
# Tape extraction resulted in errors
msg = ('One or more errors occurred while processing tape, '
'check log file for details')
tkMessageBox.showwarning("Errors occurred", msg)

# Restart the program
python = sys.executable
os.execl(python, python, * sys.argv)
if myGUI.tape.finishedFlag:
myGUI.t1.join()
if myGUI.tape.tapeDeviceIOError:
# Tape device not accessible
msg = ('Cannot access tape device ' + myGUI.tape.tapeDevice +
'. Check that device exits, and that tapeimgr is run as root')
errorExit(msg)
elif myGUI.tape.successFlag:
# Tape extraction completed with no errors
msg = ('Tape processed successfully without errors')
tkMessageBox.showinfo("Success", msg)
else:
# Tape extraction resulted in errors
msg = ('One or more errors occurred while processing tape, '
'check log file for details')
tkMessageBox.showwarning("Errors occurred", msg)

# Restart the program
python = sys.executable
os.execl(python, python, * sys.argv)

except Exception as e:
# Unexpected error
msg = 'An unexpected error occurred, see log file for details'
Expand Down
6 changes: 4 additions & 2 deletions tapeimgr/tape.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self):
self.logFileName = ''
self.checksumFileName = ''
self.initBlockSizeDefault = ''
self.finishedFlag = False
self.tapeDeviceIOError = False
self.successFlag = True
self.configSuccess = True
Expand Down Expand Up @@ -229,10 +230,11 @@ def processTape(self):
logging.error('One or more errors occurred while processing tape, \
check log file for details')

# Set finishedFlag
self.finishedFlag = True

# Wait 2 seconds to avoid race condition
time.sleep(2)
# This triggers a KeyboardInterrupt in the main thread
thread.interrupt_main()

def processFile(self):
"""Process a file"""
Expand Down

0 comments on commit 752db32

Please sign in to comment.