Pregunta

I am working on a python script to analyze astronomy images and I am trying to open a DS9 window within a python script (DS9 is a utility that allows images to be interactively viewed and analyzed). Usually I would open DS9 by going into the Linux terminal and typing:

>ds9 &

and then it would pop up in another window.

I tried to mimic this in my python script by writing the following line:

os.system('ds9 &')

When I would run the script the DS9 window would pop up but the rest of the script would not run until I closed the DS9 window. This gave me errors because the tasks that followed needed a DS9 window to be opened.

I am wondering if there is a way to open a window from within a python scripts and still have the rest of the script continue running.

Perhaps:

os.system('ds9 &')

isn't the right approach?

¿Fue útil?

Solución

You can use subprocess module.
subprocess is a newer way to spawn processes rather than using os.spawn*() or os.system().

In your case:

import subprocess
subprocess.Popen(["ds9"])

This should run ds9 in background.

See the documentation here.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top