0

How can i thread a function and itself in itself

The title may be confusing but how would i thread something like this def cat(): X=random.randint(0,1) if X==0: cat() This is not the code but how would i make the first cat and the cat in the function work at the same time

21st Aug 2018, 12:30 PM
Imagine Existance
Imagine Existance - avatar
3 odpowiedzi
+ 1
create new thread for the cat function with threading module when calling it.(when calling it inside the function) but they will never work at the same time in the example, since it stops after the function call.
21st Aug 2018, 1:17 PM
Markus Kaleton
Markus Kaleton - avatar
0
if i coppy the same function diffrent name can i reffer to it before it is concevied btw this is the og code import time from random import randint as rnum from threading import Thread def cell(e): print("new cell\n") while True: e-=1 time.sleep(1) e+=(rnum(0,15)/10) if e<=0: print("cell died") break if e>10: e-=4 time.sleep(1) cell(4) cell(15)
22nd Aug 2018, 11:36 PM
Imagine Existance
Imagine Existance - avatar
0
i dont like it because it executes the next cell than executing both
22nd Aug 2018, 11:40 PM
Imagine Existance
Imagine Existance - avatar