From 1d818568f52b695441e2423197c04e47746bd472 Mon Sep 17 00:00:00 2001 From: Thierry Zamofing Date: Thu, 1 Sep 2022 08:00:42 +0200 Subject: [PATCH] try avoid camera deadlock --- swissmx.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/swissmx.py b/swissmx.py index 1554113..58e35a7 100755 --- a/swissmx.py +++ b/swissmx.py @@ -45,7 +45,7 @@ ts=timestamp() ts.log('Import part 1/8:') import sys, os, time import json, re -import random, signal +import random, signal,threading #import Wigis #ZAC: orig. code #import jungfrau_widget #ZAC: orig. code @@ -217,6 +217,8 @@ class StartupSplash: Ui_MainWindow, QMainWindow = loadUiType("swissmx.ui") class WndSwissMx(QMainWindow, Ui_MainWindow): + sigNewCamImg = pyqtSignal() # index in self._grids + #pixelsPerMillimeter = pyqtSignal(float) #beamCameraCoordinatesChanged = pyqtSignal(float, float) addGridRequest = pyqtSignal(float, float) @@ -629,6 +631,7 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): event.ignore() def cb_update_center_widget(self, index): + _log.debug('TODO: check to not connect smultiple igNewCamImg') if index > 0: # not showing camera image _log.warning("listening to zescape") self.timer.stop() @@ -641,12 +644,16 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): try: self.cb_new_frame_sim() except AttributeError: + self.sigNewCamImg.connect(self.cb_update_img) app._camera.run(self.cb_new_frame_pv) 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() - sz=app._camera._sz + cam=app._camera + sz=cam._sz if kwargs['count']==sz[0]*sz[1]: pic=kwargs['value'].reshape(sz[::-1]) else: @@ -655,7 +662,18 @@ class WndSwissMx(QMainWindow, Ui_MainWindow): if pic.dtype==np.int16: pic.dtype=np.uint16 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): app=QApplication.instance()