Unable to thread with tufty 2040

I have a slice of code from a larger set:

luxval = 0


def lux():
    global luxval
    while True:
        lux_pwr = Pin(27, Pin.OUT)
        lux_pwr.value(1)

        lux = ADC(26)

        reading = lux.read_u16()
        print(reading)
        luxval = reading
        time.sleep(1)
    
def dis():
    while True:
        display.set_pen(WHITE)
        display.text(str(luxval), 0, 0, 320, 4)
        display.update()
        time.sleep(1)
        
_thread.start_new_thread(lux, ())
_thread.start_new_thread(dis, ())

This program is going to have at least 10 or 12 threads with these being 2. However I am unable to get them to work I get the following error:

1632  File "
<stdin>", line 76, in <module>
OSError: core1 in use
>>> 1504
1600
1616
1600
1600
1616
1600

where line 76 is _thread.start_new_thread(dis, ())

Can any provide some support as too how would go about doing this?

_thread.start_new_thread(lux, ())
_thread.exit()
_thread.start_new_thread(dis, ())

Always close one thread before trying to start another

These are endless loops.

Is there any way to run both at the same time. I noticed that the rp2040 only has 1 core so this may not be possible?

def lux():
    global luxval
    while True:
        lux_pwr = Pin(27, Pin.OUT)
        lux_pwr.value(1)

        lux = ADC(26)

        reading = lux.read_u16()
        print(reading)
        luxval = reading
        display.set_pen(WHITE)
        display.text(str(luxval), 0, 0, 320, 4)
        display.update()
        time.sleep(1)
        
_thread.start_new_thread(lux, ())

Put the work in the same loop. Why do you need to use a second core?

the main code is inside of another function. As the user naviagtes the UI the sensors function which is scanning temperature, humidity and 15 other values constantly logs the data to a file. I thought adding threading would solve this

If you are just reading values from sensors and printing out the values and save to a file you can put all of this in the same loop. No need to use the second core.

You need the second core when the main core is fully occupied on a time dependent loop and you want to do something else at the same time.