Jul-02-2020, 11:16 PM
(Jul-02-2020, 04:36 PM)HarleyQuin Wrote: It would constantly loop so whilst it doesn't seem like the code would use up much resource it doesn't seem sensible.
I'd at least add a time delay to loop every 5 minutes or something. time.sleep(300) will but 5 minutes between each check.
There are better ways to do this but i'm unsure as to what your overall goal is but sleep function should help.
Thank you for replying.
I've also thought about it.
5 minutes interval will be too large for my purpose.
1-5 millisecond will do.
To check approximate full speed I've used this code:
import time def get_second_microsecond(): """Returns current UTC second and microsecond as list""" gettime = time.time() second = int(gettime) microsecond = int(round((gettime - second), 6) * 1000000) timelist = [second, microsecond] return timelist starttime = get_second_microsecond() changingvariable = 0 comparingvariable = 1 for i in range(1000000): if changingvariable != comparingvariable: print('changing variable= {}, comparing variable= {}'.format(changingvariable, comparingvariable)) comparingvariable = changingvariable print('changing variable= {}, comparing variable= {}'.format(changingvariable, comparingvariable)) endtime = get_second_microsecond() totaldelay = (endtime[1] - starttime[1]) print('start time= {0[0]}.{0[1]}'.format(starttime)) print('end time= {0[0]}.{0[1]}'.format(endtime)) print('Total Delay= {} microsecond'.format(totaldelay))
Output:changing variable= 0, comparing variable= 1
changing variable= 0, comparing variable= 0
start time= 1593730068.643423
end time= 1593730068.788341
Total Delay= 144918 microsecond
Process finished with exit code 0
Grossly 7 million loops per second. will it not jam a part of the CPU?if I put a 5 ms delay for 100 loops:
Output:changing variable= 0, comparing variable= 1
changing variable= 0, comparing variable= 0
start time= 1593731128.280446
end time= 1593731128.816871
Total Delay= 536425 microsecond
Grossly 200 loops per second.Hmm...
OK that might be an workaround.
But I am keeping this thread as unsolved if anyone have other explanation or other workaround.
Anyway, thanks again.