try avoid camera deadlock

This commit is contained in:
2022-09-01 08:00:42 +02:00
parent d96f3cc9db
commit 1d818568f5

View File

@@ -45,7 +45,7 @@ ts=timestamp()
ts.log('Import part 1/8:') ts.log('Import part 1/8:')
import sys, os, time import sys, os, time
import json, re import json, re
import random, signal import random, signal,threading
#import Wigis #ZAC: orig. code #import Wigis #ZAC: orig. code
#import jungfrau_widget #ZAC: orig. code #import jungfrau_widget #ZAC: orig. code
@@ -217,6 +217,8 @@ class StartupSplash:
Ui_MainWindow, QMainWindow = loadUiType("swissmx.ui") Ui_MainWindow, QMainWindow = loadUiType("swissmx.ui")
class WndSwissMx(QMainWindow, Ui_MainWindow): class WndSwissMx(QMainWindow, Ui_MainWindow):
sigNewCamImg = pyqtSignal() # index in self._grids
#pixelsPerMillimeter = pyqtSignal(float) #pixelsPerMillimeter = pyqtSignal(float)
#beamCameraCoordinatesChanged = pyqtSignal(float, float) #beamCameraCoordinatesChanged = pyqtSignal(float, float)
addGridRequest = pyqtSignal(float, float) addGridRequest = pyqtSignal(float, float)
@@ -629,6 +631,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
event.ignore() event.ignore()
def cb_update_center_widget(self, index): def cb_update_center_widget(self, index):
_log.debug('TODO: check to not connect smultiple igNewCamImg')
if index > 0: # not showing camera image if index > 0: # not showing camera image
_log.warning("listening to zescape") _log.warning("listening to zescape")
self.timer.stop() self.timer.stop()
@@ -641,12 +644,16 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
try: try:
self.cb_new_frame_sim() self.cb_new_frame_sim()
except AttributeError: except AttributeError:
self.sigNewCamImg.connect(self.cb_update_img)
app._camera.run(self.cb_new_frame_pv) app._camera.run(self.cb_new_frame_pv)
def cb_new_frame_pv(self, **kwargs): def cb_new_frame_pv(self, **kwargs):
#_log.debug('new_frame_pv_cb count {}'.format(kwargs['count'])) #thrd=threading.current_thread()
#_log.debug(f'thread:{thrd.getName()}, {thrd.native_id}')
app=QApplication.instance() app=QApplication.instance()
sz=app._camera._sz cam=app._camera
sz=cam._sz
if kwargs['count']==sz[0]*sz[1]: if kwargs['count']==sz[0]*sz[1]:
pic=kwargs['value'].reshape(sz[::-1]) pic=kwargs['value'].reshape(sz[::-1])
else: else:
@@ -655,7 +662,18 @@ class WndSwissMx(QMainWindow, Ui_MainWindow):
if pic.dtype==np.int16: if pic.dtype==np.int16:
pic.dtype=np.uint16 pic.dtype=np.uint16
camera.epics_cam.set_fiducial(pic, 255) camera.epics_cam.set_fiducial(pic, 255)
self._goImg.setImage(pic) cam._pic=pic
# self._goImg.setImage(cam._pic) caused some deadlocks.
# therefore try to update the image with signals instead
self.sigNewCamImg.emit()
def cb_update_img(self):
#thrd=threading.current_thread()
#_log.debug(f'thread:{thrd.getName()}, {thrd.native_id}')
app=QApplication.instance()
cam=app._camera
self._goImg.setImage(cam._pic)
def cb_new_frame_sim(self, **kwargs): def cb_new_frame_sim(self, **kwargs):
app=QApplication.instance() app=QApplication.instance()