Skip to content

SCR303: module-level-side-effect

Library module calls system.* or does I/O when it is imported

Code SCR303
Name module-level-side-effect
Category Scripts (SCR)
Default severity warning
Enabled by default yes
Fix available no
ign-lint equivalent none

Reports calls in a project library module that run when the module is imported: at module level and in class bodies, including decorators and default argument values, but not inside function bodies, lambdas or an if __name__ == '__main__': block. Reported calls are system.* functions (also through aliases and fpmi) and the I/O builtins open, file and execfile, and time.sleep / java.lang.Thread.sleep.

These system.* calls are considered harmless and are not reported: system.util.getLogger, system.util.getGlobals (the gateway-wide dictionary modules use to keep state across reloads), system.util.getProjectName, system.util.jsonEncode, system.util.jsonDecode, every system.date.* and system.math.* function, and the system.dataset.* functions except the export* ones (they build or convert datasets without side effects). Creating objects such as system.net.httpClient() is not reported either: only functions are.

Ignition imports a library module lazily, the first time any script of any scope touches it, and again after every project save. Module-level code then runs at an unpredictable moment, in whichever scope imported it (gateway, Perspective session, Vision Client, Designer), possibly where the function does not exist or with the wrong permissions; a tag read or query that fails there makes the whole module fail to import. A sleep blocks the importing script.

setpoints = system.tag.readBlocking(["[default]Line/Setpoint"])
def target():
return setpoints[0].value

Use instead:

def target():
return system.tag.readBlocking(["[default]Line/Setpoint"])[0].value

Generated from the rule metadata by iglint generate-docs; iglint rule SCR303 prints the same page in the terminal. Source: docs/rules/SCR303.md.