td.Error: Invalid Run object

Pulling my hair out over all things Pythonesque in TD. First it was threading and delays and now it is checking for None Type and whether variables exist.
In the following I get a 'Invalid Run object error even though on the line before I print out t1 and get
<td.Run object at 0x00000482376452874562734>
My goal is to simply check if the run object called t1 exists and then to kill() it. ie stop the running delay.
Any feedback appreciated!

func = op('uncook').text
t1 = None

def onValueChange(channel, sampleIndex, val, prev):
  print('onValueChange', val)

  id1 = op('ID')[0]

  global t1
  global func

  my_list = [id1,id2,id3,id4,id5,id6]
  my_list2 = [i for i in my_list if i] 
  #delay before we set cooking false
  d:float= 2500
  if id1 is not None:
      if id1 == 0:
          print('first person is hidden') 
          op('person1').op('hold').run()      
          t1 = run(func, "ring1", delayMilliSeconds=d)
      elif id1 > 0:
          print('ASSERT first person detected t1 ',t1)
          if t1 is not None: 
              t1.kill()

@art3mis - is there a simpler example we can work from - there are a few dependencies here that are going to cloud some general run() conversation.

delayScript = 'print("hello World")'

runObj = run(delayScript, delayFrames=60)

if runObj is not None:
	print("stopping ", runObj)
	runObj.kill()

This simple example is working… so I think there’s something else at play here.

I’m thinking that the problem is when run objects are completed, they become invalid and give errors if you try to do anything with them. I’ve added this to the bug queue, but I expect some conversation about the solution. Will keep y’all up to date on this thread.

Meanwhile, you can use try: except: to figure out which run objects are invalid.

Thanks for the feedback! Will implement try:except as a possible solution. Python is so elegant in many ways, but checking if a variable exists is not one of them.

In this case, the problem is that the variable does exist, but TD considers it an error to try to access it.