While loops

hi all,

is there a way to use a while loop to recieve some data while a sensor is on like a camera in open cv etc.
Any small example is very welcome how i could stay inside the blender text editor.

At the moment is my solution to write to a csv file from pycharm and read it in blender, maybe there also a better solution because if i write data inside a while loop the data is only written to csv when the while loop is ending.

I could put the file open inside the loop to send data in every iteration but that make no sense performance whise.

I need a stream that can read the data inside the while loop to get data in real time.

Hope it make sense.

yes, but you will want to run it in its own thread, otherwise it will hang the main thread that Blender is using and Blender will appear to lock up.

You mean something like this.

import threading
import time

def loop(iterator, lenght):
    while iterator < lenght:
        iterator = iterator + 1
        print (iterator)

t = threading.Thread(target=loop, name= 'threat1', args=(0, 30))