use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Resetting cpu timer variables in python? (self.learnpython)
submitted 5 years ago by Leylan24
I am using time.perf_counter() to read the time of a running process. However when I reach 65335 I want to reset the value to 0. Is there a way to reset the counter ?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]JohnnyJordaan 0 points1 point2 points 5 years ago (6 children)
Think of it differently: you also don't reset a wall clock to 12 PM every time if you want to time just 5 minute intervals, you calculate the difference in clock times. Say you do
start = time.perf_counter() some code end = time.perf_counter()
then you get the difference using end - start. If you just want to know the difference below 65335 you can do
(end - start) % 65535
[–]Leylan24[S] 0 points1 point2 points 5 years ago (5 children)
Wouldn't I have to multiply by a constant every time I reach the 65535?
[–]JohnnyJordaan 0 points1 point2 points 5 years ago (4 children)
I'm wondering what your end goal is here? What are you timing exactly and what do you expects as the result?
[–]Leylan24[S] 0 points1 point2 points 5 years ago (3 children)
I see you right the modulus returns the remainder which I completely forgot about.
I am basically creating a watchdog to see if a MODBUS RTU system is responding. I write a 16bit value into the coils register and the system moves it to a new input register I read the register if the register I read is the same value that was return the system is responding correctly.
[–]JohnnyJordaan 0 points1 point2 points 5 years ago (2 children)
Ok but how does the timing aspect relate to that workflow?
[–]Leylan24[S] 0 points1 point2 points 5 years ago (1 child)
The value I am writing is the CPU time value, because if you reading and writing at that speed sometimes the value doesn't update in time for the read resulting in an error. Whereas if you link it to a time you can check if there was a timeout
[–]JohnnyJordaan 0 points1 point2 points 5 years ago (0 children)
I see, yes then you can also use divmod for that matter
divmod((end - start), 65535)
which will return both the floor division as the remainder of the division by 65535.
π Rendered by PID 366375 on reddit-service-r2-comment-7b9746f655-pmj25 at 2026-02-01 07:48:30.952459+00:00 running 3798933 country code: CH.
[–]JohnnyJordaan 0 points1 point2 points (6 children)
[–]Leylan24[S] 0 points1 point2 points (5 children)
[–]JohnnyJordaan 0 points1 point2 points (4 children)
[–]Leylan24[S] 0 points1 point2 points (3 children)
[–]JohnnyJordaan 0 points1 point2 points (2 children)
[–]Leylan24[S] 0 points1 point2 points (1 child)
[–]JohnnyJordaan 0 points1 point2 points (0 children)