When running a pipeline with a Jython stage we can see an exception similar to the one below appearing from time to time:
SCRIPTING_06 - Script error while processing batch: javax.script.ScriptException: ImportError: cannot import name <> in <script> at line number 3
Jython has a known issue with the thread safety of imports. From SDC version 3.13.0 there is available a solution to work around this issue. We can use a system-wide lock available with the Jython Scripting origin to synchronize imports between threads and between pipelines. In your script, acquire the lock, import all needed modules, and then release the lock.
When using the system-wide lock, the script must release the lock, even upon failure or an error. In Jython, use a try
statement with a finally
block:
try:
sdc.importLock()
import ...
finally:
sdc.importUnlock()
If a script that fails does not include the finally
block to release the lock, then no other script can use the lock until you restart Data Collector.