# Mostly Scripting

**URL:** <https://forum.inductiveautomation.com/t/mostly-scripting/10792>\
**Category:** General Discussion\
**Created:** [November 16, 2015, 2:06pm UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792 "2015-11-16T14:06:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 16, 2015, 2:06pm UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/1 "2015-11-16T14:06:16Z")

</div>

I am trying to understand the Python runspaces in Ignition and had a couple of statements/questions. Please correct me if I am wrong.

[quote][https://inductiveautomation.com/forum/viewtopic.php?f=50&t=13914&p=50718&hilit=global+variable#p50718](https://inductiveautomation.com/forum/viewtopic.php?f=50&t=13914&p=50718&hilit=global+variable#p50718)  
[https://inductiveautomation.com/forum/viewtopic.php?f=72&t=8684&p=28732&hilit=global+variable#p28732](https://inductiveautomation.com/forum/viewtopic.php?f=72&t=8684&p=28732&hilit=global+variable#p28732)[/quote]  
1) Global Python variables exist in different runspaces, therefore, a client script global variable is not visible to a gateway script global variable (and vice versa)

2) Memory tags are visible to both client and gateway runspaces.

> [@](#):
>
> [https://docs.inductiveautomation.com:8443/display/DOC/system.util.sendMessage](https://docs.inductiveautomation.com:8443/display/DOC/system.util.sendMessage)

3) system.util.sendMessage looks to be helpful.  
... but where do I obtain all clientSessionIds?

Questions:

1. When does the script manager re-initialize?

2. Can someone provide an example of a coroutine (not threading)?

3. Are memory tags shared between multiple instance of the same project?

4. Are gateway global variables shared between multiple instances of the same project?

5. I see that memory tags can be typed to some simple Java types, a dataset, or a UDT.  
Can an instance of a Python object be held in a memory tag? If so, how?

6. What kinds of serialization schemes are available to move data from client to gateway memory space?

7. Are there plans to upgrade Python to a newer version? If so, when?

Thanks  
/c

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 16, 2015, 5:59pm UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/2 "2015-11-16T17:59:26Z")

</div>

> [@](#):
>
> 1) When does the script manager re-initialize?

Whenever the project is saved.

> [@](#):
>
> 2) Can someone provide an example of a coroutine (not threading)?

I think you'll find a number of examples if you search, e.g. [juandebravo.com/2015/07/06/d ... in-python/](http://www.juandebravo.com/2015/07/06/demystifying-coroutines-in-python/)

> [@](#):
>
> 1. Are memory tags shared between multiple instance of the same project?
> 2. Are gateway global variables shared between multiple instances of the same project?

Memory tags and global variables are both defined in the gateway, and there is only one "instance" of each project ever running on the gateway.

> [@](#):
>
> 1. I see that memory tags can be typed to some simple Java types, a dataset, or a UDT.  
> Can an instance of a Python object be held in a memory tag? If so, how?

I think you can write any object you want to a tag, though the designer likely won't display anything meaningful for its value if you're looking at it.

> [@](#):
>
> 1. What kinds of serialization schemes are available to move data from client to gateway memory space?

I'm not sure what you mean, but using the client messaging would be an acceptable way to transfer data from client to gateway. You can also write to tags or execute database queries...

> [@](#):
>
> 7) Are there plans to upgrade Python to a newer version? If so, when?

We'll be upgrading to Jython 2.7 either in 7.9 or the release immediately following it.

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 17, 2015, 12:42am UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/3 "2015-11-17T00:42:18Z")

</div>

Thank you!

> [@](#):
>
> Memory tags and global variables are both defined in the gateway, and there is only one "instance" of each project ever running on the gateway.

So what happens when multiple clients are running the same project?

/c

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 17, 2015, 12:55am UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/4 "2015-11-17T00:55:06Z")

</div>

They get their own client tags, but the memory tags are shared.

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 17, 2015, 2:16am UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/5 "2015-11-17T02:16:30Z")

</div>

Sounds scary 😈 .

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 19, 2015, 11:15pm UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/6 "2015-11-19T23:15:35Z")

</div>

[quote="Kevin.Herron"][quote="cmisztur2"]Thank you!

> [@](#):
>
> Memory tags and global variables are both defined in the gateway, and there is only one "instance" of each project ever running on the gateway.

So what happens when multiple clients are running the same project?

/c[/quote]

They get their own client tags, but the memory tags are shared.[/quote]

What does this scenario look like if I have one project for 5 different machine cells and each cell needs their own instance of the project?

/c

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 20, 2015, 1:22am UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/7 "2015-11-20T01:22:52Z")

</div>

[quote=“cmisztur2”][quote=“Kevin.Herron”][quote=“cmisztur2”]Thank you!  
What does this scenario look like if I have one project for 5 different machine cells and each cell needs their own instance of the project?  
[/quote][/quote][/quote]

Tags exist as part of the gateway, independent of whether any projects exist or not.

You need to design your project or projects with that in mind.

In this case, you could have one project that had maybe a screen for each machine cell, and some configuration or indirection dictated which tags the screen actually referenced, or (less ideally) 5 separate projects that were all slightly different in some way.

---

<div class="post-metadata">

**Author:** ![cmisztur2](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmisztur2/32/4243_2.png) [@cmisztur2](https://forum.inductiveautomation.com/u/cmisztur2)\
**Post date:** [November 20, 2015, 2:30am UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/8 "2015-11-20T02:30:38Z")

</div>

[quote=“Kevin.Herron”]

Tags exist as part of the gateway, independent of whether any projects exist or not.

You need to design your project or projects with that in mind.

In this case, you could have one project that had maybe a screen for each machine cell, and some configuration or indirection dictated which tags the screen actually referenced, or (less ideally) 5 separate projects that were all slightly different in some way.[/quote]

Understood. That gives meaning to UDTs and Templates.

Thanks.

---

<div class="post-metadata">

**Author:** ![chen\_zhe](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@chen\_zhe](https://forum.inductiveautomation.com/u/chen_zhe)\
**Post date:** [December 11, 2023, 1:53am UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/9 "2023-12-11T01:53:33Z")

</div>

HI Kevin

```auto
import time
total = 0
tempa = 0
oldtotal = 0
def calculate_downtime(start):    
    global total, tempa, start_time, end_time,oldtotal
    if start == False and tempa == 0:  
        start_time = time.time()  
        tempa = 1  
    elif start == True:
         tempa = 0   
    if tempa == 1:  
        end_time = time.time()  
        total = (end_time - start_time) + oldtotal
        return total/60
    elif tempa == 0:
         oldtotal = total
         return oldtotal/60

```

When I save the project, the global variables above are reset to zero. How can I prevent them from being reset to zero

---

<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:** [December 11, 2023, 2:13am UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/10 "2023-12-11T02:13:56Z")

</div>

You are posting this in many places. This against this [forum's rules](https://forum.inductiveautomation.com/faq).

---

<div class="post-metadata">

**Author:** ![chen\_zhe](https://avatars.discourse-cdn.com/v4/letter/c/c0e974/32.png) [@chen\_zhe](https://forum.inductiveautomation.com/u/chen_zhe)\
**Post date:** [December 11, 2023, 2:31am UTC](https://forum.inductiveautomation.com/t/mostly-scripting/10792/11 "2023-12-11T02:31:22Z")

</div>

Sorry，I don't know that  
it won't be next time
