Home > Software engineering >  show date use multithreading in python
show date use multithreading in python

Time:10-07

I'm having a problem. How to show list of 50 emails|passwork on screen with 4 threads?

my_list = ["mail|pass", "Mail2|Pass@",..., "Mail50|Pass50"]

I try to use 2 for loops but data print is repeated

import  threading
...
for j in range(0,len(my_list)):
   i = j%4
   for i in range(4):
     ep = my_list[j]
     data = ep.split('|')
     email = data[0]
     pass_email = data[1]
     threads = []
     thread1 =myThread(email,pass_email)
     thread1.start()
     threads.append(thread1)
   for t in threads:
     t.join()

CodePudding user response:

You forgot to increment j:

import  threading
...
for j in range(0,len(my_list),4):
    for i in range(4):
        if i j < len(my_list)
            ep = my_list[i j]
            data = ep.split('|')
            email = data[0]
            pass_email = data[1]
            threads = []
            thread1 =myThread(email,pass_email)
            thread1.start()
            threads.append(thread1)
    for t in threads:
        t.join()
  • Related