Can two infinite loops be ran at once?
问题 I want to be able to have two while True loops running at the same time. Would this be possible? I am extremely new to Python, so I do not know how to get round this problem. This is the code I made: import time def infiniteLoop(): while True: print('Loop 1') time.sleep(1) infiniteLoop() while True: print('Loop 2') time.sleep(1) Right now, it just prints a 'Loop 1' Thanks in advance 回答1: To run both loops at once, you either need to use two threads or interleave the loops together. Method 1: