pys60线程在Symbian Python中不起作用

0 投票
2 回答
577 浏览
提问于 2025-04-17 08:35

我正在用pys60为Symbian开发一个短信应用。
我创建了一个线程来发送短信,但这个线程没有正常工作。
我希望这个线程能够在后台运行,无论应用程序是否关闭。
联系人索引是一个字典,里面存储了联系人号码和名字。

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")

它进入了“进入发送短信线程”,但之后就没有继续了。
这个发送短信的线程函数是:

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)

有没有人能告诉我,为什么这个线程没有进入,导致它无法在应用程序关闭与否的情况下继续运行?

2 个回答

0

试试下面这段代码:

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 是一个在后台运行的函数。

0

使用 threading 模块。通过这个模块创建的 Thread 线程,主线程会在程序退出之前等待它们完成。

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

在其他地方创建的线程,或者设置了 daemon 属性的线程,主线程是不会等待它们的。

撰写回答