Question

  import subprocess
  subprocess.Popen(['C:\Program Files\Nuke6.1v3\\Nuke6.1.exe', '-t', 'C:\Users\user\Desktop\\server.py'

I am currently using this to call server.py, which is setup in the following way

import sys
import os
import distutils
import shutil
import nuke

def imageScale(source,destination,scale):
    myRead = nuke.createNode("Read")
    #SET VALUES
    myRead["file"].setValue(source)
    myRead["selected"].setValue(True)
    #CREATE REFORMAT
    myReformat = nuke.createNode("Reformat")
    #SET VALUES
    myReformat["type"].setValue("scale")
    myReformat["scale"].setValue(scale)#.75)
    #SELECTION
    myRead["selected"].setValue(False)
    myReformat["selected"] .setValue(True)
    #CREATE WRITE
    myWrite = nuke.createNode("Write")

    #SET VALUES
    myWrite["file"].setValue(destination)
    myWrite["file_type"].setValue("png")
    myWrite["channels"].setValue("rgba")
    myWrite["name"].setValue("temp")
    nuke.execute("temp",1,1,1)

Would I be able to use subprocess.popen to pass in arguments to my imageScale function i.e. I pass in arguments source,destination,and scale directly from subprocess

Was it helpful?

Solution

Short answer is yes. You want to read arguments from sys.argv in your server.py.

However, If you know you have a python function and know you will be calling it from python, I would have a look at

import multiprocessing
import server

p = multiprocessing.Process(target=server.imageScale, args=(source,destination,scale))
p.start()
p.join()

Apart from being more esthetic, you are free to do other stuff between start and join.

EDIT: Actually, I am just assuming that Nuke will do the right thing with arguments. No guarantee that it will, so the second strategy is probably better for that reason too.

OTHER TIPS

subprocess just executes a process and allows communication with the new process with arguments and pipes, it can't do anything else. If you want to achieve that you need a wrapper to communicate with the parent program and call the imageScale() function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top