Ignition event scripts generally do not hold state--that is, any variables/functions/classes created in the script are discarded at the end of the script.
Ignition project library scripts, on the other hand, are run once at the top level the first time they are referenced elsewhere, and then persist until the project is edited/saved (or an parent project is edited/saved).
Put your import and your initialization of pid
in the top level (unindented) in a project library script. Put the call to execute the instance in a function within the project library script. That function would use system.tag.readBlocking()
to retrieve the process value into a local python variable for the pid
instance to use, and would use system.tag.writeBlocking()
to send the control value to an output tag.
Call that function from a gateway timer event at the desired pace.
Edit: Oy! Library script auto-import is racy, and doesn't always run once. Use the work-around here until it is fixed: