J
J
Jalal Nasirov2021-07-09 13:27:53
Python
Jalal Nasirov, 2021-07-09 13:27:53

How to write a list using streams?

hello world.

from time import sleep
from threading import Thread

all_id = [('0',), ('1',), ('2',), ('3',), ('4',), ('5',), ('6',), ('7',)]

def potok(num):
    
    if True:
        
        if num == 1:# ПОТОК 1
            
            for x in all_id:
    
                print(x[0])
        
                sleep(0.5)
                
        elif num == 2:# ПОТОК 2
            
            for x in all_id:
    
                print(x[0])
        
                sleep(0.5)
        
thread1 = Thread(target=potok, args=( 1,))

thread2 = Thread(target=potok, args=( 2,))

thread2.start()

thread1.start()

Result:
60e823ef32d27451085927.jpeg
The list can have an unlimited number of elements, so I write it in several threads in order to save time. The problem with my code is that it lists several identical elements. It is necessary that each element of the list, registered once. The order is optional.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dooMoob, 2021-07-09
@Best_Loops

I think you should first read how threads work in principle, then read how they work in python

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question