Let us say we have 10000 employees record and we want to increase the performance of processes on these records , in this case we can use the thread
So :
Tread is away to distribute the work into many processes which are running at the same time , and that will increase the performance of our server
Example :-
let us say that we want to display the multiplication table of number inserted by the user
we will define the object which contain the fields and the functions , then create four function each one make the multiplication table for the number with only 3 numbers , then we will call the four functions at the same time by using threads
from odoo import models, fields, api, _
import threading
class multiplication_table(models.Model):
_name = 'multiplication.table'
number = fields.Interger('Number', required=True)
def thread1(self):
for x in xrange(1,4):
print (self.number," * ",x,"=",self.number*x)
def thread2(self):
for x in xrange(4,7):
print (self.number," * ",x,"=",self.number*x)
def thread3(self):
for x in xrange(7,10):
print (self.number," * ",x,"=",self.number*x)
def thread4(self):
for x in xrange(10,13):
print (self.number," * ",x,"=",self.number*x)
t1= threading.Thread(target=self.thread1, args=())
t2= threading.Thread(target=self.thread2, args=())
t3= threading.Thread(target=self.thread3, args=())
t4= threading.Thread(target=self.thread4, args=())
t1.start()
t2.start()
t3.start()
t4.start()
No comments:
Post a Comment