Need to open Pycharm/Notepad++ from Maya python shelf (Windows)

46 views
Skip to first unread message

Alien Ghost Ship Animation

unread,
Jun 23, 2021, 6:02:04 AMJun 23
to Python Programming for Autodesk Maya
Hi all, we are porting all scripts since Python3 is now integrated, and need to open PyCharm/Notepad++ from within Maya to replace script editor.

MEL system() executes fine and doesn't halt maya, awaiting NP++ to close:
string $scriptsPath = `internalVar -userScriptDir`;
chdir $scriptsPath;
system("start C:/Program Files (x86)/Notepad++/notepad++.exe new_prog.mel")

Python version makes maya UI wait until NP++/Pycharm closes if using anything other than popen
import subprocess as subp

progpath=r'C:/Program Files (x86)/Notepad++/notepad++.exe'
launch=subp.Popen(progpath)
...

Since the external programs auto-save work, anything wrong with a launch.kill() shelf double-click (as long as I store & kill the proper PID of course)?

Anything else I should consider when using this method, or better ones would be appreciated. Thanks all!



Justin Israel

unread,
Jun 23, 2021, 3:26:34 PMJun 23
to python_in...@googlegroups.com
On Wed, Jun 23, 2021 at 10:02 PM Alien Ghost Ship Animation <Anim...@alienghostship.com> wrote:
Hi all, we are porting all scripts since Python3 is now integrated, and need to open PyCharm/Notepad++ from within Maya to replace script editor.

MEL system() executes fine and doesn't halt maya, awaiting NP++ to close:
string $scriptsPath = `internalVar -userScriptDir`;
chdir $scriptsPath;
system("start C:/Program Files (x86)/Notepad++/notepad++.exe new_prog.mel")

The start command should be spawning your program into a new detached background process, which causes the system function to return right away, as it sees the start command has finished.
 

Python version makes maya UI wait until NP++/Pycharm closes if using anything other than popen
import subprocess as subp

progpath=r'C:/Program Files (x86)/Notepad++/notepad++.exe'
launch=subp.Popen(progpath)
...

Well, what other approaches did you use that ended up hanging Maya? In your MEL example you prefixed your command with "start" to allow it to run in the background and then return immediately. But if you are not using that in python, then you might be blocking on the notepad process to finish. 
Running this Popen(notepad_command) is going to start the nodepad process directly and not block Maya unless you wait for the pid to complete (.wait()). However, it may be possible to start seeing zombie processes (at least on Linux/mac, not sure about windows) if you launch it this way, and the notepad command eventually finished but you never check the pid result (wait()).
 

Since the external programs auto-save work, anything wrong with a launch.kill() shelf double-click (as long as I store & kill the proper PID of course)?

Calling the kill() should end up doing the needed waitpid to prevent seeing zombie child processes. So this approach should work as long as it is actually killed this way, and not just closed from the child notepad window. It is possible to also pass the popen instance into a thread that does the wait(). You could test those situations.
 

Anything else I should consider when using this method, or better ones would be appreciated. Thanks all!



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/95da2ba1-f7c2-4626-b2c4-28c1b7945259n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages