How can I use more than one function in the same Thread?(python)

Asked

Viewed 39 times

-2

I already tried that but it says that the is not defined:

import threading as te
import time
b=[]
def c():
  global a
  a=0
  while b==[]:
    time.sleep(0.001)
    a+=0.001
def i():
  b.append(input('enter'))
  print(f'{a:.9}')
r=lambda x: print(x)
te.Thread(target=c and r('c')).start()
i()

inserir a descrição da imagem aqui

  • I could not play the error. I tried it on Linux and Windows and the result was the same c
enter

  • Never mind I figured out how to do it; Just put more than one function inside another function.

1 answer

1


Hello, this would be the solution you are looking for?

import threading
import time


def printar_um():
    for x in range(0, 5):
        print("\nprintar_um")
        time.sleep(1.0)


def printar_dois():
    for x in range(0, 5):
        print("\nprintar_dois")
        time.sleep(1.0)


def run_thread(job_function):
    job_thread = threading.Thread(target=job_function)
    job_thread.start()


if __name__ == "__main__":
    run_thread(job_function=printar_um)
    run_thread(job_function=printar_dois)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.