ericmandel / pyds9

Python connection to SAOimage DS9 via XPA
76 stars 41 forks source link

Can't run DS9 function more than one time #77

Closed kolayne closed 5 years ago

kolayne commented 5 years ago

Code I execute:

>>> import pyds9
>>> d = pyds9.DS9() #OK
>>> d.set("exit")
1
>>> d = pyds9.DS9() #Not OK :(
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/pyds9.py", line 449, in __init__
    raise ValueError('no active ds9 running for target: %s' % target)
ValueError: no active ds9 running for target: ds9

Both times I run the DS9 function, ds9's window opens, but when I run it for the second time, it sleeps for about 5-6 seconds and then gives an error. After the first ds9 closes, there is a zombie process left in the memory by subprocess, maybe it causes the problem?..

ericmandel commented 5 years ago

I hate to have to say this, but doing repeated exits/restarts seems to work for me with the latest pyds9 from github and python 2.7 (MacOS 10.14):

>>> d = pyds9.DS9()
>>> d.set("exit")
1
>>> d = pyds9.DS9()
>>> d.set("exit")
1
>>> d = pyds9.DS9()
>>> d.set("exit")
1
>>> d = pyds9.DS9()
>>> d.set("exit")
1
>>> d = pyds9.DS9()
>>> d.set("exit")
1

Is there any chance that you have another xpans process running with a different XPA_METHOD? Because if pyds9 is starting ds9 correctly but the subsequent pyds9 calls to xpaaccess are not returning the new ds9 access point, it might indicate a mixup between xpans and ds9 regarding the communication method.

kolayne commented 5 years ago

Is there any chance that you have another xpans process running with a different XPA_METHOD?

I don't think so, how can I check it?

ericmandel commented 5 years ago

Try:

ps guwax | egrep xpans

and see how many xpans processes you have running. Also, when ds9 is running, try:

xpaget xpans
DS9 ds9 gs 7f000001:55025 eric

to see which method is being used. The 4th arg above tells you inet sockets are being used (its showing ip:port). If Unix sockets are being used, you'll see a file name instead.

It would be good to try the above xpaget command after the error happens ... the error is claiming that there are no ds9 instances present, which we don't believe ...

kolayne commented 5 years ago

ps guwax | egrep xpans:

After starting python3: nikolay 2813 0.0 0.0 15652 1020 pts/2 S+ 21:13 0:00 grep -E --color=auto xpans After importing pyds9:

nikolay   2825  0.0  0.0   6780  1908 pts/0    S+   21:13   0:00 /usr/local/lib/python3.6/dist-packages/xpans -e
nikolay   2828  0.0  0.0  15652  1108 pts/2    S+   21:13   0:00 grep -E --color=auto xpans

After closing first ds9:

nikolay   2825  0.0  0.0      0     0 pts/0    Z+   21:13   0:00 [xpans] <defunct>
nikolay   3411  0.0  0.0  15652  1008 pts/2    S+   21:18   0:00 grep -E --color=auto xpans

After trying to create new DS9 object: nikolay 3538 0.0 0.0 15652 1000 pts/2 S+ 21:19 0:00 grep -E --color=auto xpans again

kolayne commented 5 years ago

Oh, I've just found the solution 😅 In order to execute the xpaget xpans command, I had to install the xpa-tools package. So, the problem became fixed after sudo apt-get install xpa-tools. Thank you!

ericmandel commented 5 years ago

OK ... but just for the record, I still don't understand what is going on here! Please let me know which OS (looks like Linux ... which one?) you are using and I'll put this problem on my "look into some day" list.

kolayne commented 5 years ago

Yes, Linux Mint 19.1, 4.15.0-46-generic kernel, ds9 v8.0.1, pyds9 v1.8.1, python3.6.7