system functions

48 views
Skip to first unread message

Todd Widup

unread,
Sep 1, 2015, 1:58:01 PM9/1/15
to python_in...@googlegroups.com
I have several functions that run on the system from within Maya..creating directories, checking things in and out of our source control system,etc

I know I read this someplace but I cant recall how to do it..how can I run those functions from within Maya, but not lock Maya up during that time.

thanks
-todd

--
Todd Widup
Creature TD / Technical Artist
to...@toddwidup.com
todd....@gmail.com
www.toddwidup.com

Emre Yilmaz

unread,
Sep 1, 2015, 2:27:47 PM9/1/15
to python_in...@googlegroups.com
I've used subprocess for this.

import subprocess

myCmd = "ping -n 5 8.8.8.8"

# Wait
subprocess.Popen( myCmd, shell=False, bufsize=4096 ).wait()

# No wait
subprocess.Popen( myCmd, shell=False, bufsize=4096 )

--
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/CABBPk35MGR64r2sOEDXAdFh-oCwYBV2frAHo89VX%3DiJZFPJcfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Sep 1, 2015, 2:30:20 PM9/1/15
to python_in...@googlegroups.com

Subprocess is really only good for external processes, and less so for Python functions.

Threading to the rescue!

import time
import threading

def my_system_function():
  print("Doing something for 5 seconds..")
  time.sleep(5)
  print("Done!")

threading.Thread(target=my_system_function).start()

--
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/CABBPk35MGR64r2sOEDXAdFh-oCwYBV2frAHo89VX%3DiJZFPJcfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Emre Yilmaz

unread,
Sep 1, 2015, 2:46:00 PM9/1/15
to python_in...@googlegroups.com
Yeah, good point. Didn't catch that those system / pipeline cmds were themselves also python.

Justin Israel

unread,
Sep 1, 2015, 4:07:26 PM9/1/15
to python_in...@googlegroups.com

They could still be run through subprocess if you package your functions into a proper main application. And then you just run it with arguments that control which service(s) will be performed. A benefit is that it is easy to stop them by killing a process id. The downside is if you need to actually talk to them actively, it is more complicated than threads.
With threads, to get them to stop before their own action chooses to end, you have to build in cancellation to the function you run, like having them check a stop condition.


Todd Widup

unread,
Sep 1, 2015, 4:11:36 PM9/1/15
to python_in...@googlegroups.com
ok, will look into these ideas..thanks all


For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages