×
Namespaces

Variants
Actions
Revision as of 20:06, 11 September 2009 by nayan_trivedi (Talk | contribs)

Archived:Create a list of platform threads in PySymbian

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N95
CompatibilityArticle
Keywords: threading
Created: (09 Sep 2007)
Last edited: nayan_trivedi (11 Sep 2009)
{{{width}}}

Contents

Overview

Create a simple list of thread. The threads need for call manipulate many asyncronous process.

Modules need

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

Defining Thread

In this code the thread class is create. The class sum numbers and store in result list after run

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() # Define above normal process
x = self.sum()
processResult.append({ 'thread' : self.tx, 'result': x })
print "%s %s" % (self.tx,x)

Main process

The main process create threads class with random number and start process with it 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()
82 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×