# Using locks in Jython scripts

**URL:** <https://forum.inductiveautomation.com/t/using-locks-in-jython-scripts/115911>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [June 9, 2026, 2:59pm UTC](https://forum.inductiveautomation.com/t/using-locks-in-jython-scripts/115911 "2026-06-09T14:59:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul.longtine](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.longtine/32/10599_2.png) [@paul.longtine](https://forum.inductiveautomation.com/u/paul.longtine)\
**Post date:** [June 9, 2026, 2:59pm UTC](https://forum.inductiveautomation.com/t/using-locks-in-jython-scripts/115911/1 "2026-06-09T14:59:53Z")

</div>

Are there any sharp edges and warnings when using a `ReentrantLock` from `java.util.concurrent.locks` in a script module? Is there advantages to just using `import threading` with a `threading.RLock`?

The use case is around locking an object on the globals map (in `system.util.globals`), but it may be accessed from perspective script transforms, gateway timer scripts, message handlers, etc.

Any wisdom is appreciated!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 9, 2026, 4:03pm UTC](https://forum.inductiveautomation.com/t/using-locks-in-jython-scripts/115911/2 "2026-06-09T16:03:17Z")

</div>

The implementation of `threading.RLock` is a java ReentrantLock under the hood. The jython class is a context manager and can be used with the `with` statement.

Dabbling in `system.util.globals` requires some care--especially to not accidentally include any custom code in stored objects. Since you tagged this topic as v8.1, you should also be aware of this issue:

> [@\[IGN-6503\]Project Library Script Initialization Races](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636):
>
> Are you annoyed by pseudo-random breakage in Ignition project library scripting? Odd top-level constants being garbled, or operations in the top level that have side effects running twice? Or more? Not happening much, but always around project edits, and sometimes even on gateway restart? Yeah, me too. frowning_face Poking around under the hood back in the spring, for a module development task, I ran across some problematic IA bytecode and pinged some people. But it went nowhere, as I co…
