I created a scene-based script in pythonista. I'd like to have a worker thread update some data periodically. The idea would be that the worker could download some data from a web site (via urllib) every so often and update member variables of a class which would then draw the results in its normal draw callback.
I first tried the thread module and thread.start_new_thread. As an initial test my thread function looked similar to the following (going off memory now).
def MyThreadFunc(self):
while True:
someVar += 1
time.sleep(1.0)
My expectation was that about every second the number would increment in the display. It didn't do this, though. It would seem to update sometimes, then go for a while before updating again. Like the timing was random.
I then thought I'd try the threading module. I derived a class from Thread, created an instance, called start and had similar code to the above. This time it hung pythonista.
So what is the best way to run a worker thread in the background with a loop similar to whats shown above?