×
Namespaces

Variants
Actions

Archived:Uso simples de Thread, em PySymbian

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Cria uma lista simples de thread. As threads necessitam manipular o processo de chamada assíncrono.

Article Metadata

Testado com
Aparelho(s): Nokia N95

Compatibilidade
Artigo
Palavras-chave: threading
Tradução:
Por maiconherverton
Última alteração feita por hamishwillee em 31 May 2013

Contents

Módulos necessários

import sys
from appuifw import *
import os
import e32
import threading
import random

Definindo a Thread

Neste código da classe a thread é criada. A classe de números de soma armazenam na lista de resultados depois de executar

class process(threading.Thread):
value = 0
tx = 0
def sum(self):
x = 1
for i in range(1, self.value):
x = x + i
return x
 
def run(self):
e32.ao_yield() # Definir acima processo normal
x = self.sum()
processResult.append({ 'thread' : self.tx, 'result': x })
print "%s %s" % (self.tx,x)

Processo principal

O processo principal cria uma classe thread com número aleatório e o processo começa com a thread.

processList = [] 
processResult = []
 
class Principal(threading.Thread):
def pop(self):
for i in range(200):
p = process()
p.value = random.randint(1, 10000)
p.tx = i
processList.append(p)
 
for i in processList:
i.start()
 
def run(self):
e32.ao_yield()
self.pop()
 
principal = Principal()
principal.start()

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 31 May 2013, at 04:10.
63 page views in the last 30 days.
×