socket connection is the first thing i thought of, but that implies coding some socket listening logic in the child process, was hoping to avoid that.

im exploring some other possibilities like talking via pipes which is what i think you are talking when issuing commands to the stdin, or the other one ive seen is using shared memory between the two processes with some sort of datastructure like a queue.

Ive read some interprocess communication in Operating Systems CS subject but of all, the option im more familiar with is using sockets... and i think for what im trying to do is a bit overkill.

Thanks to both.

El 25/02/2018 a las 2:24, Justin Israel escribió:


On Thu, Feb 22, 2018, 2:58 AM Marcus Ottosson <konstrukt...@gmail.com <mailto:konstrukt...@gmail.com>> 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_script1 import 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 python_inside_maya+unsubscr...@googlegroups.com
    <mailto:python_inside_maya+unsubscr...@googlegroups.com>.
    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 python_inside_maya+unsubscr...@googlegroups.com <mailto:python_inside_maya+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA02F0DUD9C63AS6fWhi7VRPjBWq04j00zt-RAqyQTKR6w%40mail.gmail.com <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA02F0DUD9C63AS6fWhi7VRPjBWq04j00zt-RAqyQTKR6w%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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/b666a8a6-8e25-e210-7edf-f761d0189ac5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to