Python, make a multi-point code.



  • Annex which creates 3 flows and they must at the same time infinitely carry out this

    1. print.
    2. print.
    3. print. with threading library

    That's how I got it, but somehow the terminal only has one.

    import time
    from threading import Thread
    a = 1
    

    def potok1():
    a = 1

    while a == 1:
    time.sleep(1)
    print('1 cекунда')

    def potok2():
    a = 1

    while a == 1:
    time.sleep(2)
    print('2 секунды')

    def potok3():
    a = 1

    while a == 1:
    time.sleep(3)
    print('3 секунды')
    th = Thread(target=potok1, args=())
    th1 = Thread(target=potok2, args=())
    th2 = Thread(target=potok3, args=())
    th.start()
    th1.start()
    th2.start()
    th.join()
    th1.join()
    th2.join()



  • It's only "1" because the program has completed the main flow.

    Add.

    th.join()
    th1.join()
    th2.join()
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2