Is there a way to run two loops (for loops, while loops,...) at the same time in Ppython? For a simple example I want to run two for loops in parallel (at the same time) not linearly (one after one). If that possible please show me for the loops in this script:
for x in range (0,10):
print('hello world')
for x in range(0,10 ):
print ('welcome to the world')
The easiest way is to use numba:
@jit(nopython=True, parallel=True)
def simulator(out):
# iterate loop in parallel
for i in prange(out.shape[0]):
print('hello world')
print('welcome to the world')
another way is to use asyncio but it is more complex to handle.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.