On Thu, Feb 22, 2018, 2:58 AM Marcus Ottosson <[email protected]> wrote:
> Yes, when you import my_script, it is effectively “run”. So what you can > do is launch 1 instance of mayapy, and pass it a single script that imports > the others. > > $ mayapy my_script.py > > *my_script.py* > > import other_script1import other_script2 > > guess what im asking is if there you can specify the process id for > example to the Popen method and have it use the process if it already > exists or create one if it doesnt > > This probably isn’t what you’re looking for. Yes, you can get the process > ID from a Popen instance, but unless you devise an interprocess > communication server/client between your processes, you haven’t got that > many options left for telling the mayapy you find to run another script. > Just to expand on this answer a little bit, there are a few different options with varying complexity. Your subprocess can open a commandPort, and your main process can issue commands to it via a socket connection. The Maya subprocess can start reading from stdin and you can issue instructions to it by writing to the stdin of your Process object. You can use some non-maya interprocess communication like jsonrpc, ZMQ, or some other RPC or message bus. But this is probably overkill of you don't already have them as available libraries. If you have redis, Rabbitmq, or some other task queue already running, you could make it the broker for pushing in requests from the main process and having the subprocess read them out to execute. CommandPort or talking to stdin of the subprocess are probably the easiest choices. > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCFwBwRq-rzjgu9hbg8G7BDWkXLNR5VGTAN55SzMjbX3Q%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCFwBwRq-rzjgu9hbg8G7BDWkXLNR5VGTAN55SzMjbX3Q%40mail.gmail.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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA02F0DUD9C63AS6fWhi7VRPjBWq04j00zt-RAqyQTKR6w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
