How can i dectect when a repl is stopped with python
Can you please be more specific, and provide a link to your repl?
Can you please clarify what you mean by ādetect when it is stoppedā?
i am trying to make it idle so that when you log on it adds everything you would have gotten while you were offline. For this, i need to know when the repl stops so that i can record ātime.time()ā so that i can then, when the person logs on again, find out how much time they have been offline and add what they earned.
I see that, I was thinking.
would inviting u to the repl help?
Best I can say is have a thread running that is constantly updating the time, then when the repl stops you will have the time of when it stopped.
If that solves your problem, please mark my answer as the solution.
Could you show the snippet where you made the threading?
ok here it is:
def idle():
while True:
a=time.time()
b=time.gmtime(a)
c=time.strftime("%S", b)
with open("time.txt", "w") as f:
f.write(c)
Thread(target=idle).start()
Does the code return an error? If so, what is the error? If not, what is it doing versus what you expect? You should probably have the code sleep for a second in-between file updates, so you donāt use excessive amounts of RAM.
it isnāt returning an error, its just not writing the items to the file everytime the loop goes
I see. I will check something and get back to you.
This writes to the file, although I donāt think it writes what you expect it to:
import time
from threading import Thread
def idle():
while True:
a=time.time()
b=time.gmtime(a)
c=time.strftime("%S", b)
with open("time.txt", "w") as f:
f.write(c)
time.sleep(1)
Thread(target=idle).start()
while 1:
time.sleep(1)
ok iāll try that code
thatās perfect, thank you!