xzos/PyZDDE

Exception Type Error when I run a PyZDDE script repeatedly

olfduh opened this issue · 8 comments

Hi,

I have some issue when I run a script using PyZDDE multiple times. The first time it works without problems, only the consecutive executions will give an error message. The script stills seems to execute everything, however. Am I maybe missing some commands to close the link properly?

Thanks in advance!

Olf

Here is the scrip I am using:

import pyzdde.zdde as pyz

link = pyz.PyZDDE()
link.zDDEInit()

link.zLoadFile(r'C:\Users\user\test_seq.zmx')
print link.zSetField(1,2,3)

link.zSaveFile(r'C:\Users\user\test_seq_bearbeitet.zmx')
pyz.closeLink()
link.zDDEClose()

Here is the Python console output:

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Imported NumPy 1.8.1, SciPy 0.14.0, Matplotlib 1.3.1
+ guidata 1.6.1, guiqwt 2.3.2
Type "scientific" for more details.
>>> runfile('Z:/projekte/P100223_Conti_3D_HUD/Simulationen/ZemaxPython.py', wdir=r'Z:/projekte/P100223_Conti_3D_HUD/Simulationen')
141013
fieldData(xf=2.0, yf=3.0, wgt=1.0, vdx=0.0, vdy=0.0, vcx=0.0, vcy=0.0, van=0.0)
>>> runfile('Z:/projekte/P100223_Conti_3D_HUD/Simulationen/ZemaxPython.py', wdir=r'Z:/projekte/P100223_Conti_3D_HUD/Simulationen')
UMD has deleted: pyzdde.zcodes.zemaxoperands, pyzdde.config, pyzdde, pyzdde.utils.pyzddeutils, pyzdde.zcodes, pyzdde.ddeclient, pyzdde.utils, pyzdde.zcodes.zemaxbuttons, pyzdde.zdde
Exception TypeError: "'NoneType' object is not callable" in <bound method PyZDDE.__del__ of PyZDDE(appName='', appNum=1, connection=False, macroPath=None)> ignored
141013
fieldData(xf=2.0, yf=3.0, wgt=1.0, vdx=0.0, vdy=0.0, vcx=0.0, vcy=0.0, van=0.0)
>>> 

Hi Olf,

I think pyz.closeLink() and link.zDDEClose() are actually doing close to the same thing, so you should remove one of them.

Hi Olf,
Catherine is right. Because of the last two lines (which are essentially the same), your program crashes. I acknowledge that it might be confusing that there are 3 functions to close links and at least 2 for creating links. This is mainly because when PyZDDE was created first, it tried to emulate how MZDDE (the MATLAB toolbox) worked. Later, I found it extremely frustrating to type so much boiler plate code to start communicating with zemax. So, the two helper functions to quickly create and close links were created. Here is the most basic way to using PyZDDE:

import pyzdde.zdde as pyz
ln = pyz.createLink()
# communicate with Zemax 
ln.zGetVersion() # example
...
ln.close()

Please do let us know if that solved the problem so that we can close this issue.

Hi,
thanks for the quick reply! I tried your example but still get the same issue.Both the normal console and IPython give me the same error message. Do you have any idea how to trace down the problem?

import pyzdde.zdde as pyz
ln = pyz.createLink()
# communicate with Zemax 
ln.zGetVersion() # example
ln.close()
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Imported NumPy 1.8.1, SciPy 0.14.0, Matplotlib 1.3.1
+ guidata 1.6.1, guiqwt 2.3.2
Type "scientific" for more details.
>>> runfile('C:/Users/user/ZemaxPython.py', wdir=r'C:/Users/user')
141013
>>> runfile('C:/Users/user/ZemaxPython.py', wdir=r'C:/Users/user')
UMD has deleted: pyzdde.zcodes.zemaxoperands, pyzdde.config, pyzdde, pyzdde.utils.pyzddeutils, pyzdde.zcodes, pyzdde.ddeclient, pyzdde.utils, pyzdde.zcodes.zemaxbuttons, pyzdde.zdde
Exception TypeError: "'NoneType' object is not callable" in <bound method PyZDDE.__del__ of PyZDDE(appName='', appNum=1, connection=False, macroPath=None)> ignored
141013
>>> runfile('C:/Users/user/ZemaxPython.py', wdir=r'C:/Users/user')
UMD has deleted: pyzdde.zcodes.zemaxoperands, pyzdde.config, pyzdde, pyzdde.utils.pyzddeutils, pyzdde.zcodes, pyzdde.ddeclient, pyzdde.utils, pyzdde.zcodes.zemaxbuttons, pyzdde.zdde
>>> runfile('C:/Users/user/ZemaxPython.py', wdir=r'C:/Users/user')
UMD has deleted: pyzdde.zcodes.zemaxoperands, pyzdde.config, pyzdde, pyzdde.utils.pyzddeutils, pyzdde.zcodes, pyzdde.ddeclient, pyzdde.utils, pyzdde.zcodes.zemaxbuttons, pyzdde.zdde
Exception TypeError: "'NoneType' object is not callable" in <bound method PyZDDE.__del__ of PyZDDE(appName='', appNum=1, connection=False, macroPath=None)> ignored
>>> 

I have never seen such an error message before. I also googled about the message "UMD has deleted", and found some issues related to the Spyder IDE. Are you using a Spyder IDE? If you are, then can you check to see if it is related to Spyder? Also, see if you can execute the code outside of Spyder. (By the way, I have used PyZDDE in all types of environment -- Spyder, IPython console, IPython Notebook, WinPython, plain Python interpreter, etc ... but I never saw such an error message. Also, can you type the lines in a interactive IPython environment and see if you can import pyzdde.zdde ? If you are able to import, then see if you are able to create a link. Also, try to print the string representation of the link object to see if PyZDDE could create a DDE link, assigned an application number, etc. For, example see the following 3 lines that are from a interactive session in IPython QtConsole.

In [1]: import pyzdde.zdde as pyz

In [2]: ln = pyz.createLink()

In [3]: ln
Out[3]: PyZDDE(appName='ZEMAX', appNum=1, connection=True, macroPath=None)

Let us know.

Hi,
that seems to be indeed a Spyder related issue. If I open the file in idle, everything is ok. Thanks for the help. I'll try to see if I can solve the issue for Spyder as well (it is just much more convenient to use). I'll let you know how it is going

No problem, Olf. By the way, I use Spyder quite regularly both with Anaconda and Enthought's EPD, and never faced this issue. It is indeed very convenient. It might just be some configuration issue. Try disabling the UMD module as described in http://stackoverflow.com/questions/13876306/spyder-umd-has-deleted-module and see if it works. For now, I am closing this issue.

Regards,
Indranil.

The answer in the stackoverflow thread solves the issue. I just had to navigate to

"Tools > Preferences > Console > Advanced settings > User Module Deleter"
and deactivate the option "Show reloaded modules list"

Now I don't get an error message anymore :)