Skip to content

neelay-16/Python-Infinite-Loop

Repository files navigation

Python-Infinite-Loop

In this project, we'll explore how to use Python threading to create a simple program that prints "aaaaaa" and "bbbbbb" simultaneously. It's a fun way to demonstrate the power of multithreading and can be a starting point for more complex projects.

Preview

parallel_loop.mp4

Description

Importing the threading module. This line imports the threading module, which provides a way to work with threads in Python.

image

Defining the lwa function. Here, lwa is a function that contains an infinite loop. Inside the loop, it repeatedly prints the string "aaaaaa" to the console.

image

Similar to lwa, the lwb function also has an infinite loop that prints the string "bbbbbb" to the console repeatedly.

image

Creating two threads 'thread_a' and 'thread_b'.Each thread is associated with one of the previously defined functions, lwa and lwb, using the target parameter. This prepares the threads to execute those functions concurrently.

image

The start() method is called on both thread_a and thread_b to begin their execution. This is where the concurrency comes into play. Once the threads are started, they will independently execute the lwa and lwb functions concurrently.

image

You should see "aaaaaa" and "bbbbbb" alternating in your console, demonstrating the simultaneous execution of both threads.

Feel free to experiment and modify the code as you like. This project serves as a basic example of Python threading, and you can extend it to create more complex multithreaded applications.

About

Run 2 python functions parallely in infinite loops without using while loop!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published