0

I am developing a sms app for symbian using pys60. I have created a thread for sending the sms but theread is not working.
I want this thread to run in background, irrespective of applicaton closed or not.
contact index is a dictionary with contact nos and names.

def send_sms(contact_index):
    import thread
    appuifw.note(u"entered to send sms thread")
    tid = thread.start_new_thread(send_sms_thread, (contact_index, ))
    appuifw.note(u"completed")

it enters "entered to send sms thread" but doesnt go after that.
the function sens_sms_thread is :

def send_sms_thread(contact_index):
    appuifw.note(u"entering the thread in sending sms in loops")
    for numbers in contact_index:
        name = contact_index[number]
        appuifw.note(u"sending sms to %s ." % name)
        messaging.sms_send(numbers, message_content, '7bit', cb, '')
        e32.ao_sleep(30)

can anyone tell me why it is not entering into this thread which will run in background inrrespective of application closed or not?

sam
  • 18,509
  • 24
  • 83
  • 116

2 Answers2

0

Try the next snippet:

if __name__=='__main__':

    th = e32.ao_callgate(Udp_recv)
    thread.start_new_thread(th,())

    for i in range(10):
        tmp = (str(i)+data)[0:10]

Udp_recv is the function running in background.

Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62
Zhi Li
  • 1
0

Use the threading module. Threads created by this module will be waited on by the main thread before the process exits.

thread = threading.Thread(target=send_sms_thread, args=(contact_index,))
thread.start()

Threads created elsewhere, or with the daemon attribute are not waited for.

Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
  • I tried threading.therad but it waits. I dont want it to wait till sms sending finishes. i want this send_sms_thread function should run in background even if i closed the application. – sam Dec 18 '11 at 10:25
  • @sam: Then you need to create a new process, likely a daemon process. – Matt Joiner Dec 18 '11 at 10:34
  • yes. thanks for replies.i dont have idea about creating the same. can you kindly let me know if u know it. – sam Dec 18 '11 at 10:37