Passing to job object to Event process

Hey,

I’m trying to pass the job object in an event plugin, to a process.
The recommended way seems to be to use “self.RunProcess”, but then I can’t pass the job across.

Would be good to even pass the job id and get the job object in the process.

BTW I don’t want to rely on the web service for this.

The job object is indeed returned in a number of our event plugins and then ALL job info is accessible. Can you share some code?

[code]class MyListener( DeadlineEventListener ):

def __init__( self ):
    self.OnJobSubmittedCallback += self.OnJobSubmitted

def Cleanup( self ):
    del self.OnJobSubmittedCallback

def OnJobSubmitted( self, job ):
    print job.JobId[/code]

Lots of examples here as well: github.com/ThinkboxSoftware/Dea … tom/events

Sorry, yeah I should have explained with some code.

[code]class MyListener( DeadlineEventListener ):

def __init__( self ):
    self.OnJobSubmittedCallback += self.OnJobSubmitted

def Cleanup( self ):
    del self.OnJobSubmittedCallback

def OnJobSubmitted( self, job ):
    self.RunProcess("python", script_path)[/code]

Its in the python script being run, that I would like to access the job object.

Dump job object to json and pass to Python (not tested, but you get the idea)

[code]from System import *

from Deadline.Events import *
from Deadline.Scripting import *
from Newtonsoft.Json import *

import os

def GetDeadlineEventListener():
return MyListener()

def CleanupDeadlineEventListener( eventListener ):
eventListener.Cleanup()

class MyListener( DeadlineEventListener ):

def __init__( self ):
    self.OnJobSubmittedCallback += self.OnJobSubmitted

def Cleanup( self ):
    del self.OnJobSubmittedCallback

def OnJobSubmitted( self, job ):
	jsonJobObject = JsonConvert.SerializeObject( job )
	ClientUtils.LogText( "json object: %s" % jsonJobObject )
	# then pass the entire job object as json string/dict to your python process
	# or then use Python's json to modify the job object dump and pass what you prefer
    ProcessUtils.SpawnProcess( "python", jsonJobObject )

[/code]

I’m having trouble getting feedback from the script, even with redirecting the stdout;

process = ProcessUtils.SpawnProcess("python", script_path, os.getcwd(), ProcessWindowStyle.Hidden, True) ProcessUtils.WaitForExit(process, -1)

Is “SpawnProcess” different from “RunProcess”?

I keep forgetting that RunProcess is also available in the eventPlugin and not just the DeadlinePlugin class. Both should work.

Is the process exiting correctly?

print process.ExitCode

You probably need to define an absolute path to your “python.exe” as well such as:

pythonExe = "c:/python27x64/python.exe" args = "" process = ProcessUtils.SpawnProcess(pythonExe, args, os.getcwd(), ProcessWindowStyle.Hidden, True) ProcessUtils.WaitForExit(process, -1) print process.ExitCode if process.StandardOutput != None: output = process.StandardOutput.ReadToEnd() print output

When I pass the “jsonJobObject” the monitor freezes and become unresponsive:(

Also by spawning a process I don’t have access to the standard Deadline libraries, as I do in the event plugin. Is there no way of running a python script through the Deadline executable you get with “sys.executable”?
I could then just pass a job id, and retrieve the job object through the Deadline libraries (I think?).

I don’t understand what your trying to do here? Can you provide more context here? You are already executing inside of cPython 2.7…why do you need to leave it?

You are right about being in the right environment.

I thought the best practice for event plugins was to execute a process?

Currently when I need to import custom libraries I need to modify sys.path, is that the intended use?

I thought the best practice for event plugins was to execute a process?
It really depends on what your doing and whether an external process is required?

Additional paths can be added in repo options:
docs.thinkboxsoftware.com/produc … n-settings

or you can use sys.path to append, as you prefer. There are many examples of how we do this with Draft.

It really depends on what your doing and whether an external process is required?

Its not required:) The event plugin I’m making has settings for adding additional python search paths.

Thanks Mike for discussion:)