Python not importing module "random" when writing event plug

My event plugin contains the following:

import random, string randomString = "".join(random.choice(string.ascii_uppercase + string.digits) for x in range(5))

This works fine in python on mac terminal, however deadline generates the following error:

[code]=======================================================
Error Message

global name ‘random’ is not defined

=======================================================
Slave Log

An error occurred in the “OnJobFinished” function in events plugin ‘SlatedQuicktimeGen’: An error occurred in function “OnJobFinished” the event plugin script file “/Volumes/DeadlineRepository/events/SlatedQuicktimeGen/SlatedQuicktimeGen.py”: global name ‘random’ is not defined (Deadline.Events.DeadlineEventPluginException)
at Deadline.Events.DeadlineEventPlugin.HandlePythonError (System.String message, System.Exception e) [0x00000] in :0
at Deadline.Events.DeadlineEventPlugin.OnJobFinished (Deadline.Jobs.Job job, System.String[] auxiliaryFilenames) [0x00000] in :0
at Deadline.Events.DeadlineEventManager.OnJobFinished (Deadline.Jobs.Job job, System.String[] auxiliaryFilenames, Deadline.Controllers.DeadlineController deadlineController) [0x00000] in :0

=======================================================
Error Type

UnboundNameException

=======================================================
Error Stack Trace

at IronPython.Compiler.PythonGlobal.GetCachedValue () [0x00000] in :0
at IronPython.Compiler.PythonGlobal.get_CurrentValue () [0x00000] in :0
at (wrapper dynamic-method) object:_generator$1149 (System.Runtime.CompilerServices.Closure,Microsoft.Scripting.MutableTuple)[/code]

The problem is that IronPython (Deadline 5’s default Python engine) doesn’t support the random module. You do have a few options though:

  1. Use the Python.NET engine instead. This uses the native Python bundle that ships with Deadline. You can tell Deadline to use the Python.NET engine by making this the first line in your event plugin script:
#Python.NET

Note that in Deadline 6, the IronPython engine has been removed, and all scripts will now use native Python.

  1. The other option is to use .NET’s Random class, since both IronPython and Python.NET allow you to use .NET classes and functions:
    msdn.microsoft.com/en-us/library … andom.aspx

Hope that helps!

  • Ryan