سؤال

I have python function and I am running that process in maya. I want to run that function as a another process so maya will be still responsive and I can continue working on maya.

from multiprocessing import Process
def test_func(node):
   # I have some crazy functions in here
   pass

def run_test():
   p = Process(target=test_func, args=(items,))
   p.daemon = True
   p.start()

This is a test function only . I want to just show what I was trying to do. Any idea what is the smart way to start a process without disturbing maya ?

Thanks a lot

هل كانت مفيدة؟

المحلول

This may not be obvious to everyone, since you sort of glazed over a key issue pretty quickly... But you are trying to use multiprocessing within a session of Autodesk Maya. That, to my knowledge, doesn't work.

For the high-level reasons, which I am sure others can give more detail on, multiprocessing.Process wants to fork the Maya process and continue running. That means it needs to copy the entire maya image (which could be over 1GB of memory if you are doing a lot of stuff in your scene), and continue running. Anything you do via the Maya API would be in a completely different process, in a different scene graph. Also you are very likely to deadlock, as all of the various synchronization primitive states from the main process are now copied as-is to the new space.

You are better off sticking with a threading solution in Maya, or shelling out to an external process. Even with threading though, you have some limited ability to interact with the Maya API, and they provide utils for executing calls into the main thread and even waiting on their results.

Again, anyone else with more low-level knowledge of process forking and deadlocking, please feel free to expand this answer.

نصائح أخرى

I haven't done any python multi threading, only c++, but unless Process implicitly uses multi threading, it won't run at the same time. Look up documentation for the threading module which is part of the standard library.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top