Script Library reloading and Project Inheritance

I’m playing around with multi-project inheritance trees, for example where two runnable projects inherit from a single “Global” project, to see how project saves impact inherited script libraries, and i’m seeing odd results that I can’t explain.

I set something dumb up just for testing… I know you shouldn’t perform tag reads/writes within the root of a script library. However…

I have this script library defined in my Global project (which is not overridden in either of the two inheriting Main projects):

tagPath = '[default]Testing/Test 2'
oldVal = system.tag.readBlocking(tagPath)[0].value
r = system.tag.writeBlocking(tagPath, oldVal + 1)
system.util.getLogger('BOB').info('{} -> {}'.format(oldVal, r))

Every time the library reloads it should increment the Test 2 tag value by 1.

  • If I save the Global project, it increments 1 (I kind of expected it to flakily increment 1 or 2 depending on the speed that each Main project reloads the script library…)
  • If I save the “Main” project, it increments 1. Edit: If I set the GSP to the Global project, it doesn’t increment at all.
  • If I save the “Main2” project, it doesn’t increment at all.

I’m just looking to understand what’s happening here. I would have expected saving Main2 would also increment the tag value by 1, but it’s not. And why does saving Global not write 1 or sometimes 2?

Projects defined:

Edit:

Note: the Main project is the global scripting project (GSP).

It seems to have to do with the GSP, but I would have expected a change to an inherited script library would reload it in all inherting projects which would then run it and therefore write to the tag in all locations. I added a lock to get rid of the race condition where two threads could read the current tag value at the same time and hence increment by 1 always instead of 2:

First - is this 8.1 or 8.3?

Second - don't use tags as your counter object - too race-y. Just store an int in globals if you want an accurate count.

It’s 8.3. I tried using a global variable as well but had the same “issue”, but in that case it’s due to different scopes I think… it depends where you read the value of the global key from as to what value you’ll see.

Do keep in mind that each leaf project, and the GSP if not a leaf itself, will all have their own interpreters. Only system.util.globals is shared across the JVM.

Would this not fix the raceyness with tags?

Yes, until some other programmer stomps on your too-common name. (One of the reasons system.util.globalVarMap() takes a namespace argument.)

Of course, but I point you back to here :stuck_out_tongue:

Good thing you made it a screenshot, so desperate future visitors cannot copy/paste it... :frowning:

2 Likes