# \[IGN-6503\]Project Library Script Initialization Races

**URL:** <https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 14, 2024, 8:51pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636 "2024-11-14T20:51:28Z")\
**Posts on this page:** 19\
**Page:** 2

<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:** [October 12, 2025, 8:10pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/21 "2025-10-12T20:10:39Z")

</div>

> [@mazeyrat](#):
>
> functions in the try/finally blocks are not detected in designer

That is why I did not recommend using an outer `try`, but to do error checking in the functions themselves.

This v8.1 workaround is not perfect, cannot be perfect, and will never be perfect. If you need this to be perfect, upgrade to v8.3.

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [October 22, 2025, 7:52pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/22 "2025-10-22T19:52:29Z")

</div>

I just installed v8.3.1 and turned off the workaround I had in place (i.e. a decorator on every custom class definition using a thread lock and cache stored in project globals to only allow one class definition to exist for each class).

Unfortunately, at least in the designer, I am seeing the same problems I was before. I have a class defined in one module which I import into multiple others, but for some reason the module with the class definition gets executed repeatedly and some callers end up with different class definitions than others. Maybe this is a separate issue from what @pturmel was talking about, but it remains a significant challenge to development in Ignition.

I wonder now that the race condition problem should be fixed with the import mechanism, if this is happening because imports are not exactly the same everywhere and whatever is being used as a primary key is different for the same code module depending on how the module is being imported/accessed.

- One caller may import the class directly from my module (e.g. “from shared.custom import MyClass”) while another caller may just import the module and access the class as an attribute (e.g. “import shared.custom; shared.custom.MyClass”).
- In an attempt to create a flat interface for callers, I sometimes define a private package and a public module which imports from the private package. External callers import from the public module. This is meant to be similar to how ` __init__.py` can work in python, where it imports from the modules inside the package, avoiding the need of the caller to import from each individual module. There are then imports inside `shared._custom` between modules as well as imports by external callers made using the `custom` public module.

```shell
  
  shared/
    _custom/
      module_a
      module_b

  custom: import from shared.\_custom.module_a/b/c

```

---

<div class="post-metadata">

**Author:** ![Clancy\_Cavanaugh](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@Clancy\_Cavanaugh](https://forum.inductiveautomation.com/u/Clancy_Cavanaugh)\
**Post date:** [October 22, 2025, 8:00pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/23 "2025-10-22T20:00:11Z")

</div>

Importing from project library scripts is known to cause problems. Instead of importing you should be using the full path/name of the resource you would normally import.

```python
# Don't use import
from shared.x import y
# instead call it as
shared.x.y()

```

> [@Import from global and project script library failing randomly](https://forum.inductiveautomation.com/t/import-from-global-and-project-script-library-failing-randomly/18822/2):
>
> Try not importing it at all. Just call shared.util.MWESLogging.getLog(). Due to object lifetimes in the gateway, it is unwise to ever import anything from shared.\* or project.\*. Just use the full names wherever you need them. It shouldn't be a problem in the client either, but the designer also has weirdness. Import all you want from java. That is a pure jython operation and is effectively bulletproof. Other than the fact you can't use wildcards. See this topic:

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [October 22, 2025, 8:06pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/24 "2025-10-22T20:06:01Z")

</div>

Thanks, @Clancy_Cavanaugh , that might work, but at this point I think I have a few hundred thousand lines of code. Updating every import statement in every script module/event script/tag script/etc. is not feasible for me at this point. If I were able to start fresh, that is definitely what I would try.

---

<div class="post-metadata">

**Author:** ![Clancy\_Cavanaugh](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@Clancy\_Cavanaugh](https://forum.inductiveautomation.com/u/Clancy_Cavanaugh)\
**Post date:** [October 22, 2025, 8:13pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/25 "2025-10-22T20:13:49Z")

</div>

Probably still worth it to fix. Even if you put your decorator back in, you can run into issues with some running scripts using the old versions until they are reinitialized.

I believe I remember there being a memory leak possibility as well, but that may have only been if you are trying to persist something with system.util.getGlobals().

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [October 22, 2025, 8:23pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/26 "2025-10-22T20:23:24Z")

</div>

I would get cranking on refactoring your code. Importing project library scripts is known to be full of issues.

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [October 24, 2025, 1:36pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/27 "2025-10-24T13:36:07Z")

</div>

While I appreciate the flexibility of Ignition, from my personal perspective it has been challenging sometimes to discern what the "official" solution is from IA vs something which may work now but may also break in a future release. It would have helped me a great deal, coming from a Python background, to maybe have the video tutorials and documentation make mention of things which may not work as one might expect given that background. Specific mention of issues around custom classes, imports between scripting modules, and which libraries to use for handling different problems, might have helped in avoiding long-term growing pains.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [October 24, 2025, 3:45pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/28 "2025-10-24T15:45:17Z")

</div>

Regarding libraries the consensus is

1. First party libraries are preferred aka the `system.*` namespace
2. Java libraries are second if you cannot work a solution with the first group of functions
3. Jython libraries are last espeically anything regarding networking you should 100% not use the jython libraries as there are known issues

Great thread here too with a lot of good info [Do's and Don'ts when developing First Project with Ignition?](https://forum.inductiveautomation.com/t/dos-and-donts-when-developing-first-project-with-ignition/93592)

---

<div class="post-metadata">

**Author:** ![robertm](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@robertm](https://forum.inductiveautomation.com/u/robertm)\
**Post date:** [October 27, 2025, 12:25pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/29 "2025-10-27T12:25:49Z")

</div>

There are definitely some areas in the docs and tutorials that actively promote bad habits. Binding full UDTs comes to mind.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 30, 2025, 11:03pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/30 "2025-10-30T23:03:50Z")

</div>

> [@robertm](#):
>
> that actively promote bad habits. Binding full UDTs comes to mind.

There's another I saw from memory where tag _values_ were being sent to a popup instead of the tag paths… 😬 that would definitely confuse newbies when they try to go and write to them in the popup..

The content should need to go through a dev first, or an experienced set of eyes who has scada design experience, as that's the most relevant. Software application devs don't always have the experience to know what the end user wants or how they will use it. (Even scada devs don't always know exactly how the operators will ~~break~~ use the scada!)

[![](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e4c57b0b8defb4517dc232de386d10f916194794.jpeg "Square Hole!") ](https://www.youtube.com/watch?v=6pDH66X3ClA)

---

<div class="post-metadata">

**Author:** ![louagejasper](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/louagejasper/32/86311_2.png) [@louagejasper](https://forum.inductiveautomation.com/u/louagejasper)\
**Post date:** [November 5, 2025, 12:13pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/31 "2025-11-05T12:13:44Z")

</div>

So it's fixed but not really fixed? Or is it fixed when you import consistently around all your projects?

---

<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:** [November 5, 2025, 12:50pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/32 "2025-11-05T12:50:15Z")

</div>

The race condition described in this topic (parallel initialization threads corrupting the script module) is fixed in v8.3. In v8.1, project library auto-import is unlocked. As [noted above](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/8), the attempt to fix this with a script manager lock crashed and burned due to AB-BA deadlock with jython's own import lock.

The fix in v8.3 uses the jython import lock to also guard the library auto-importer. Adding a lock check to a previously unlocked fast path is a likely performance impact.

Note that the jython `import` statement **always** takes and then releases the import lock, every time it executes. This is the primary reason you should never place any import statement inside a function or method--you will have lock contention when busy. Ignition's auto-importer only takes that lock when necessary, IIUC. The auto-importer's fast path is also the reason you should never import from project library scripts at all--avoid lock contention on startup, too.

---

<div class="post-metadata">

**Author:** ![louagejasper](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/louagejasper/32/86311_2.png) [@louagejasper](https://forum.inductiveautomation.com/u/louagejasper)\
**Post date:** [November 5, 2025, 3:29pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/33 "2025-11-05T15:29:12Z")

</div>

Ah ok, I'm not familiar with import locks or guards, but what I understand:  
importing at the top of my script is always safe in 8.3?

---

<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:** [November 5, 2025, 3:37pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/34 "2025-11-05T15:37:21Z")

</div>

> [@louagejasper](#):
>
> my script

If you mean the top of a project library script, yes. You should not use import anywhere in an event script.

---

<div class="post-metadata">

**Author:** ![louagejasper](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/louagejasper/32/86311_2.png) [@louagejasper](https://forum.inductiveautomation.com/u/louagejasper)\
**Post date:** [November 5, 2025, 3:59pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/35 "2025-11-05T15:59:30Z")

</div>

Perfect, that is wonderful news to me!

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [June 9, 2026, 10:20pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/36 "2026-06-09T22:20:20Z")

</div>

> [@pturmel](#):
>
> ```python
> # The following must remain at the end. There *must* be error checking
> # above to ensure this executes.
> initLock.release()
> 
> ```

Hi Phil, could you wrap the whole module code in a try and put that release in the `finally`? Or at least everything after those first lines

---

<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 10, 2026, 12:28am UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/37 "2026-06-10T00:28:04Z")

</div>

That breaks the function sidebar. As Lionel noted in comment #20.

---

<div class="post-metadata">

**Author:** ![ignition\_user243](https://avatars.discourse-cdn.com/v4/letter/i/59ef9b/32.png) [@ignition\_user243](https://forum.inductiveautomation.com/u/ignition_user243)\
**Post date:** [June 18, 2026, 6:02pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/38 "2026-06-18T18:02:20Z")

</div>

We tend to take a similar approach and haven't ran into any issues. We have multiple scripts in our project library that are called on events or on startup scripts. We often instantiate variables and set them equal to 'None' and then let a function set their corresponding values when called. We haven't ran into any issues with this but we could be naive. I should note that the initialization of the project scripting library does not call any of our functions. Our functions are only called on events.

---

<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 18, 2026, 6:24pm UTC](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636/39 "2026-06-18T18:24:50Z")

</div>

> [@ignition\_user243](#):
>
> Our functions are only called on events.

The reproducer I supplied does the same. The issue is that all defined gateway startup, timer, and tag change events are called at gateway startup, or project restart, _ **in parallel** _ (multiple threads). See comment #2 for guidance on when you should or should not use the work-around.

[Previous page](https://forum.inductiveautomation.com/t/ign-6503-project-library-script-initialization-races/98636.md?page=1)
