#!/usr/bin/python3 import threading, time from random import * class cal(): def __init__(self, i, a, b): self.i = i self.a = a self.b = b def add(self, c): print("thread", self.i, "starts", self.a, self.b, c) time.sleep(2) s = self.a + self.b + c print("thread", self.i, "ends: ", self.a, self.b, c, "sum: ", s) for i in range(10): a = randint(1, 10) b = randint(1, 10) c = randint(1, 10) obj = cal(i, a, b) t = threading.Thread(target=obj.add, args=(c,)) t.start()
How to do multithrading of a simple function?
Messages In This Thread |
How to do multithrading of a simple function? - by ratanbhushan - Nov-17-2017, 09:43 AM
RE: How to do multithrading of a simple function? - by heiner55 - Nov-17-2017, 02:32 PM
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
got SyntaxError while building simple function | zarize | 2 | 2,145 |
Feb-14-2020, 10:51 AM Last Post: zarize |
|
Simple statistics with range function | Pythonlearner2019 | 2 | 2,148 |
Nov-25-2019, 05:25 PM Last Post: Pythonlearner2019 |
|
Cannot get simple i/o to function. | jerryi | 10 | 6,785 |
Jul-27-2019, 06:22 PM Last Post: jerryi |
|
Need help with a simple function | WorldPark | 4 | 2,676 |
Apr-26-2019, 12:28 PM Last Post: perfringo |
|
Why this simple function doesnt work? | blackknite | 8 | 4,035 |
Jan-05-2019, 12:32 PM Last Post: buran |
|
Simple Function Problem, please help | ShadowWarrior17 | 16 | 7,127 |
Jan-03-2018, 09:29 PM Last Post: ShadowWarrior17 |
|
Simple Function Call | PappaBear | 2 | 3,188 |
Apr-04-2017, 11:12 PM Last Post: PappaBear |
Users browsing this thread: 2 Guest(s)