Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How do I run two python loops concurrently?
You will need to use a multiprocessing library. You will need to spawn a new process and provide the code to it as an argument. For example,
from multiprocessing import Process
def loop_a():
for i in range(5):
print("a")
def loop_b():
for i in range(5):
print("b")
Process(target=loop_a).start()
Process(target=loop_b).start()
This might process different outputs at different times. This is because we don't know which print will be executed when.
Advertisements
