'Python3 threading, using double function

I want to get which output like this;

[+] Trying <here number>
Hello 1000
Hello 1001
Hello 1002
.
.
.
8
Hello 1009
.
.
.
Hello 9999

But for me, output is just this;

[+] Trying 1000
[+] Trying 1001
[+] Trying 1002
[+] Trying 1003
[+] Trying 1004
[+] Trying 1005
.
.
.

[+] Trying 9999

Code

import sys
from concurrent.futures import ThreadPoolExecutor

def t(payload):
    print("Hello " + str(payload))
    
p = 0

def times(a):
    p += 1
    
    if p%8 == 0:    
        print("8") 

    t(a) 
         
 
for i in range(1000, 10000, 1):
    ThreadPoolExecutor(50).submit(times, i)
               
    sys.stdout.write('\r[+] Trying %s' % str(i))

Can you help me about what I'm doing false?

I think code should run like this:

  1. Program should use 50 threads
  2. In for loop, it should execute times function with i parameter
  3. Times function should say 8 when i is divisible by 8


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source