SCR302: sleep-in-event-script
time.sleep or Thread.sleep in a Perspective event script
| Code | SCR302 |
| Name | sleep-in-event-script |
| Category | Scripts (SCR) |
| Default severity | warning |
| Enabled by default | yes |
| Fix available | no |
| ign-lint equivalent | none |
What it does
Section titled “What it does”Reports calls to time.sleep and java.lang.Thread.sleep (also through
imports and aliases such as from time import sleep) in Perspective
event script actions, script transforms, property change scripts,
component message handlers and component extension functions.
Only calls that run directly when the script runs are reported: a call
inside a nested def or lambda (typically a function handed to
system.util.invokeAsynchronous) runs elsewhere and is not reported.
Custom methods are not checked, because callers may run them on a
background thread.
Why is this bad?
Section titled “Why is this bad?”These scripts run on the gateway in the session's (or binding's) thread.
Sleeping blocks it: other events of the session queue up behind the
sleeping script, bindings stop updating and the page appears frozen.
Schedule delayed work with system.util.invokeAsynchronous or a timer
instead.
Example
Section titled “Example”def runAction(self, event): system.tag.writeBlocking(["[default]Line/Start"], [True]) time.sleep(2) system.tag.writeBlocking(["[default]Line/Start"], [False])Use instead:
def runAction(self, event): system.tag.writeBlocking(["[default]Line/Start"], [True]) def reset(): time.sleep(2) system.tag.writeBlocking(["[default]Line/Start"], [False]) system.util.invokeAsynchronous(reset)Generated from the rule metadata by iglint generate-docs; iglint rule SCR302 prints the same page in the terminal. Source: docs/rules/SCR302.md.