views:

27

answers:

1

I'm using positioning.position(). but this function is blocking. I want to be able to run another function while the GPS is being measured.

thanks

+1  A: 

I'm not familiar with the S60, but if it supports threading here's an example of doing two functions at once:

import threading
import time

def doit1():
    for i in range(10):
        time.sleep(.1)
        print 'doit1(%d)' % i

def doit2():
    for i in range(10):
        time.sleep(.2)
        print 'doit2(%d)' % i

t = threading.Thread(target=doit2)
t.start()
doit1()
t.join()
print 'All done.'

Hope this helps.

Mark Tolonen
what is the function of t.join?if doit1 for exmple is the function that measures gps and doit2 is the UI function, How can I know that the GPS result parameter was assigned in the end of the measurement and can be accessed from the second function?
Day_Dreamer
another thing, if I understood, this can be a simple way to implement timer? just by defining a function that "sleeps" for some time interval. Can I use more than 2 asynchronous functions in the solution you suggested? How can it be done?
Day_Dreamer
@Day_Dreamer: t.join() waits in the main thread for t to exit. For timers, there is a threading.Timer class. You can also create and start more than one thread. For fancier threads, subclass Thread. See the docs: http://docs.python.org/release/2.6.5/library/threading.html#thread-objects
Mark Tolonen
Please accept the answer if you like it ;^)
Mark Tolonen
I will, thank you :)
Day_Dreamer