On Wed, Jul 18, 2018, 6:49 PM Ruchit Bhatt <ruchitinnewfush...@gmail.com>
wrote:

> I tried your example & its working fine. Thanks
>
> *In script Editor*
> import subprocess
> import cPickle
>
> mayapy_path = r'C:/Program Files/Autodesk/Maya201x/bin/mayapy.exe'
> script_path = r'E:/multi_test.py'
>
> proc_obj = subprocess.Popen(mayapy_path + ' ' + script_path + ' -po',
> stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> result = cPickle.load(proc_obj.stdout)
> print result
>
> *multi_test.py*
> import multiprocessing
> from time import time
> import cPickle
> import sys
>
> ## Simple func to eat up cpu power.
> def whileFunc(z):
>     while z < 100000:
>         z += 1
>     return z
>
> if __name__ == "__main__":
>     ## Get current time
>     currtime = time()
>
>     ## How often to run (just a test value)
>     N = 10000
>     ## Just a list with 1s
>     myList = [1]*N
>
>     nrOfProcessors = multiprocessing.cpu_count()
>
>     ## Set our pool of processors
>     po = multiprocessing.Pool(nrOfProcessors)
>
>     ## create the threads
>     res = po.map_async(whileFunc, myList)
>
>     ## If we pass a -po flag, pickle the output and write it out
>     if '-po' in sys.argv[1:]:
>         results = len(res.get())
>         cPickle.dump(results, sys.stdout, -1)
>         sys.stdout.flush()
>         sys.exit(0)
>
>     print 'This value below should be a 1000:'
>     print len(res.get())
>     print 'time elapsed:', time() - currtime
>
>

Awesome. Glad that it worked with subprocess. One more suggestion. You
might want to try calling it like this :


proc_obj = subprocess.Popen([mayapy_path, script_path, ' -po'] ,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc_obj.communicate()
result = cPickle.load(out)

If you don't need to send stdin to your process, no need to create a pipe.
And you should use communicate to avoid a deadlock of your child process
produces lots of stdout and stderr.


> --
> 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_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/2f4122d0-ff64-4ba9-8bfa-71e7bad7f0f7%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/2f4122d0-ff64-4ba9-8bfa-71e7bad7f0f7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2R78so%3DJYDTyj%2BzHh3Vqe382EkaW5pctZ5Vtj4roQCYg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to