0

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

Day_Dreamer
  • 3,311
  • 7
  • 34
  • 61

1 Answers1

2

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
  • 166,664
  • 26
  • 169
  • 251
  • 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 Jul 31 '10 at 19:46
  • 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 Jul 31 '10 at 20:08
  • @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 Aug 01 '10 at 01:35