Hi!
I am having a very queer problem with threading and using a particular library. The final application is simple - when the library function is called, perform some other tasks simultaneously.
Here is an initial code I wrote to check that threading was all ok -
Code:
import thread
import e32
flag = 1
s = "Hi!!!"
def d():
e32.ao_sleep(3)
return "Hello"
def decode():
global s
print s
s = d()
print s
global flag
flag = 0
def main():
global flag
flag = 1
i = 0
thread.start_new_thread(decode,())
while (flag):
print i,flag
i = i+1
e32.ao_sleep(0.01)
print s
main()
Tha above works perfectly fine. When the function is called, I get the output of the while loop, that shows me a stream of numbers. All is fine.
However, when I try the same thing with an external library -
Code:
import thread
import e32
import ext_lib
flag = 1
s = "Hi!!!"
def decode():
global s
print s
s = ext_lib.d()
print s
global flag
flag = 0
def main():
global flag
flag = 1
i = 0
thread.start_new_thread(decode,())
while (flag):
print i,flag
i = i+1
e32.ao_sleep(0.01)
print s
main()
The phone appears to hang! The only output I got was the following -
Could the external function be eating up on so much of the resources (processor) that the other threads are unable to run? But if this is so, isn't the whole point of threading lost?
Thanks