wavefrontshaping / slmPy

A simple Python module based on wxPython to interact with spatial light modulators handled as secondary monitors.
Other
63 stars 26 forks source link

Every run requires start of a new Kernel #8

Closed Denbo313 closed 2 years ago

Denbo313 commented 2 years ago

Hello,

I am trying to use your slmpy on python 3.9 for operating a SLM with this sample code:

slm = slmpy.SLMdisplay(isImageLock = False) resX, resY = slm.getSize() testIMG = np.zeros([resY,resX]).astype('uint8') t0 = time.time() for i in range(100): slm.updateArray(testIMG,sleep = 0.1) print (time.time() - t0) slm.close()

The first run works fine until the point of closing the slm. When I want to do another run, I get this error message:


wxAssertionError Traceback (most recent call last) E:\Programas\Anaconda3_64\lib\site-packages\slmpy\slmpy.py in OnNewImage(self, event) 68 69 def OnNewImage(self, event): ---> 70 self.Window.UpdateImage(event) 71 72

wxAssertionError: C++ assertion "wxThread::IsMain()" failed at ....\src\msw\thread.cpp(1333) in wxMutexGuiLeaveOrEnter(): only main thread may call wxMutexGuiLeaveOrEnter()!

After a restart of the Kernel I can run the program again. I guess there is something wrong with the assignment or accessing of the main thread, but I am not familiar with the wx library yet...

Would appreciate your help :)

Cheers!

wavefrontshaping commented 2 years ago

Hi,

Hmm. I never had this issue but I tried on a Windows computer and I was able to reproduce the error. It seems that it is because I use the main GUI thread inside a thread (in order to refresh images from the command line without blocking the code). This is, from the start, not something we are supposed to do, and the origin of this issue.

As far as I can tell, there may be no solution for that except rewriting everything with another framework.

I will keep looking but I do not have much hope... Sorry

Denbo313 commented 2 years ago

Hey,

thank you for your response. I guess there cant be much done then... I saw that pygame should allow now the use of two monitors. Maybe its possible to implement it there now.

Cheers!