How can I shut down the deadline worker from DeadlineEventListener in Python? The worker is the machine that will execute the event. So, the Python script will be running inside the worker machine
The DeadlineEventListener is triggered on event calls listed under Event Plugins documentation
To restart the worker, you would need to send a remote command that would need a Worker name argument. You can get the worker name if you run the plugin script and call it from any “Slave” events listed in the above Event Plugins documentation.
Here is an example of the an function we use in our Spot Event Plugin python script under “DeadlineRepository/events/Spot/Spot.py” on line #1566:
def _CloseWorkerApplication(self, slaveName):
# type: (str) -> bool
"""
Send Deadline Worker a command to shutdown the currently running Worker app.
"""
try:
deadlinePath = os.environ['DEADLINE_PATH']
slaveExe = os.path.join(deadlinePath, "deadlineslave")
# Set DeadlineSlave path differently on Windows.
if sys.platform == 'win32':
slaveExe = os.path.join(deadlinePath, "deadlineslave.exe")
if self.verLog:
print("Shutting down Worker: {}".format(slaveName))
arguments = [slaveExe]
arguments.extend(["-shutdown", "-nogui"])
proc = subprocess.Popen(args=arguments, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
if self.verLog:
print(stdout)
print(stderr)
if proc.returncode == 0:
return True
print("WARNING: Worker shutdown failed.")
except:
print("WARNING: Worker shutdown exception.")
print(traceback.format_exc())
return False
I hope this would be helpful for you to use this as a reference to script your own event plugin.