0% found this document useful (0 votes)
4 views3 pages

Python Threading Examples and Usage

Uploaded by

MARAMMA THALLI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Python Threading Examples and Usage

Uploaded by

MARAMMA THALLI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import threading

import time

def square(numbers):

for num in numbers:

[Link](0.2)

print("square is: ",num*num)

def cube(numbers):

for num in numbers:

[Link](0.2)

print("cube is",num*num*num)

list=[1,2,3]

ini_time=[Link]()

t1=[Link](target=square,args=(list,))

t2=[Link](target=cube,args=(list,))

[Link]()

[Link]()

[Link]()

[Link]()

[Link](1)

print("Hello")

print("Time taken:",[Link]()-ini_time)
import time

from threading import *

class Ravi(Thread):

def run(self):

for i in range(5):

print("Ravi ")

[Link](0.1)

class College(Thread):

def run(self):

for i in range(5):

print("college")

[Link](0.1)

th1=Ravi()

th2=College()

[Link]()

[Link]()

[Link]()

[Link]()

import threading

def hello_world():

print("Hello world!")

thr=[Link](target=hello_world)

[Link]()
import threading

def hello_world():

for i in range(3):

print("Hello world!")

def welcome():

for i in range(3):

print("welcome")

t1=[Link](target=hello_world)

t2=[Link](target=welcome)

[Link]()

[Link]()

-----------------------------

import _thread

import time

def print_name(name, *arg):

print(name, *arg)

name="Ravi Degree College."

_thread.start_new_thread(print_name, (name, 1,8))

_thread.start_new_thread(print_name, (name, 3, 2))

[Link](0.5)

You might also like