Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Perpetual timing
#1
As another use of a timer, I'm trying to do something like this:
import time

start = time.time()
y = input("What is 4 * 3?")
end = time.time()
while (end-start) < 4:
    if y=="12":
        end = time.time()
        print("it took", (end-start), "seconds")
    else: quit()

start = time.time()
z = input("What is 6 * 6?")
That is, wait until four seconds have elapsed before moving on if not input has been submitted.

Problem is the program stops and waits until input is submitted (when I did enter 12, I saw a running tab of elapsed time until four seconds... pretty cool!).

Is there a way to query continuously whether input has been submitted? If it hasn't then I would have it check time to see if four seconds have passed.
Reply
#2
Mark17 Wrote:Is there a way to query continuously whether input has been submitted?
I have a working solution in this post which uses the built-in selectors module.
Reply
#3
(Oct-23-2019, 09:52 PM)Gribouillis Wrote:
Mark17 Wrote:Is there a way to query continuously whether input has been submitted?
I have a working solution in this post which uses the built-in selectors module.

Is that OS specific? I run Windows 10 and I got a whole bunch of tracebacks:

C:\Users\drkle\Desktop\Desktop Transfer Material\Miscellaneous\Coursera\Python>timerprogram1.py
Enter passcode: Traceback (most recent call last):
File "C:\Users\drkle\Desktop\Desktop Transfer Material\Miscellaneous\Coursera\Python\timerprogram1.py", line 18, in <module>
main()
File "C:\Users\drkle\Desktop\Desktop Transfer Material\Miscellaneous\Coursera\Python\timerprogram1.py", line 10, in main
pairs = sel.select(timeout=5)
File "C:\Users\drkle\AppData\Local\Programs\Python\Python37-32\lib\selectors.py", line 323, in select
r, w, _ = self._select(self._readers, self._writers, [], timeout)
File "C:\Users\drkle\AppData\Local\Programs\Python\Python37-32\lib\selectors.py", line 314, in _select
r, w, x = select.select(r, w, w, timeout)
OSError: [WinError 10093] Either the application has not called WSAStartup, or WSAStartup failed
Reply
#4
Normally, the selectors module has been added to python precisely to write OS independent code. It means that it should work in Windows too. I cannot answer the issue that you're bringing about Windows because I don't know this OS well enough. From my search engine's results, it seems to me that it is not a Python issue. You could perhaps try the fix from this video.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Timing actions with Python dangermaus33 0 1,003 Apr-19-2022, 10:08 PM
Last Post: dangermaus33
  Inconsistent counting / timing with threading rantwhy 1 1,757 Nov-24-2021, 04:04 AM
Last Post: deanhystad
  Synchronization/Timing Problem quest 5 2,973 Mar-31-2021, 10:26 PM
Last Post: quest
  Timing of a while loop stylingpat 4 6,790 Mar-31-2021, 10:48 AM
Last Post: stylingpat
  Assigning Data from one column to another with different associated timing interval alexafshari 1 1,947 Apr-30-2020, 03:59 PM
Last Post: pyzyx3qwerty
  Frequency and timing of psycopg2 commits acecase 0 2,069 Nov-01-2019, 05:50 PM
Last Post: acecase
  Timing input Mark17 2 2,280 Oct-23-2019, 08:25 PM
Last Post: Mark17
  Timing functions with multiprocessing mntfr 3 4,995 Nov-18-2018, 06:00 AM
Last Post: woooee
  GPIO output timing help needed skid 5 4,047 Jan-23-2018, 04:12 PM
Last Post: skid
  change timing on py script kwfreverie 2 3,108 Dec-16-2017, 07:35 PM
Last Post: kwfreverie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020