You are on page 1of 4

Practices for Lesson 2:

Advanced Features in Python

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
1 Practices for Lesson 2: Advanced Features in Python
Practices for Lesson 2
Overview
In these practices for this lesson, you will learn to develop and run Python applications for building
a banking application using OOPS concept, multithreading, file handling, connecting to SQLite
database, create student table and query the table based on the conditions.

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
2 Practices for Lesson 2: Advanced Features in Python
Practice of 2-3: Creating threads and executing multithreading
applications
Overview
In this practice, you will learn to create threads and perform multithreading within a process.

Assumptions: You should have completed Practices for 1-3


Tasks:

1. Double click on Python IDLE shortcut on your local Desktop to start the Python Shell.
2. Click File in the Menu and select New File from the drop down.
3. Save the file by clicking File in the Menu and select Save option from the drop down.
4. Save the file as Multithreading.py on your local file system.
5. Copy and paste the below code in Multithreading.py file. The code consists of functions
to find the square and cube of a number as shown in the below screenshot.

import threading

def square(num):
print("Square: {}".format(num * num))

def cube(num):
print("Cube: {}".format(num * num * num))

thread1 = threading.Thread(target=square, args=(8,))


thread2 = threading.Thread(target=cube, args=(8,))

# start thread1
thread1.start()
print("\n")
# start thread2
thread2.start()

# wait until thread1 gets executed


thread1.join()

# wait until thread2 gets executed


thread2.join()

6. Save Multithreading.py file and click Run in the Menu and select Run Module option
from the drop down to run the program
7. On successful execution, verify the output as shown below.

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
3 Practices for Lesson 2: Advanced Features in Python
8. Close the file and close Python Shell, by clicking on ‘X’ icon in the Python Shell window.

Copyright © 2020, Proton Expert Systems & Solutions. All rights reserved
4 Practices for Lesson 2: Advanced Features in Python

You might also like