Skip to content

Commit

Permalink
allow manually clearing shared memory; temporarily disabled Windows d…
Browse files Browse the repository at this point in the history
…rop-down menu

This closes #40: I don't think there's a safer (and yet automatic) way to do so...
  • Loading branch information
leofang committed May 24, 2019
1 parent bf90eca commit 770b7d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nsls2ptycho/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,5 @@ def clean_shared_memory(pid=None):
s = SharedMemory("/"+shm)
s.close_fd()
s.unlink()

print("Done.")
15 changes: 15 additions & 0 deletions nsls2ptycho/ptycho_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PyQt5.QtWidgets import QFileDialog, QAction

from nsls2ptycho.ui import ui_ptycho
from nsls2ptycho.core.utils import clean_shared_memory
from nsls2ptycho.core.ptycho_param import Param
from nsls2ptycho.core.ptycho_recon import PtychoReconWorker, PtychoReconFakeWorker, HardWorker
from nsls2ptycho.core.ptycho_qt_utils import PtychoStream
Expand Down Expand Up @@ -83,6 +84,7 @@ def __init__(self, parent=None, param:Param=None):
self.menu_export_config.triggered.connect(self.exportConfig)
self.menu_clear_config_history.triggered.connect(self.removeConfigHistory)
self.menu_save_config_history.triggered.connect(self.saveConfigHistory)
self.actionClear_shared_memory.triggered.connect(self.clearSharedMemory)

self.btn_MPI_file.clicked.connect(self.setMPIfile)
self.btn_gpu_all = [self.btn_gpu_0, self.btn_gpu_1, self.btn_gpu_2, self.btn_gpu_3]
Expand Down Expand Up @@ -124,6 +126,11 @@ def __init__(self, parent=None, param:Param=None):
self.ck_weak_obj_flag.setEnabled(False)
#self.cb_alg_flag. addItem("PIE")
#self.cb_alg2_flag.addItem("PIE")
# TODO: find a way to register the live windows so that they can be opened anytime
self.menuWindows.setEnabled(False)
#self.actionROI.setEnabled(False)
#self.actionMonitor.setEnabled(False)
#self.actionScan_points.setEnabled(False)

#if self.menu_save_config_history.isChecked(): # TODO: think of a better way...
self.retrieveConfigHistory()
Expand Down Expand Up @@ -864,6 +871,14 @@ def showNoPostProcessingWarning(self):
print("[WARNING] Post-processing is turned off. No result will be written to disk!", file=sys.stderr)


def clearSharedMemory(self):
message = "Are you sure you want to clear the shared memory segments currently left in /dev/shm? "\
"The safest way to do so is to ensure you have only one window (that is, this one) opened on this machine."
ans = QtWidgets.QMessageBox.question(self, "Warning", message, QtWidgets.QMessageBox.Yes, QtWidgets.QMessageBox.No)
if ans == QtWidgets.QMessageBox.Yes:
clean_shared_memory()


def setMPIfile(self):
filename, _ = QFileDialog.getOpenFileName(self, 'Open MPI machine file', directory=self.param.working_directory)
if filename is not None and len(filename) > 0:
Expand Down

0 comments on commit 770b7d2

Please sign in to comment.