My timer won't work properly, since it keeps printing forever, not what I want.
I've already tried re-organizing the script in many ways, but the result is always the same.
import time CommandInput = input() #execution [uptime] def uptime(y): while 1 == 1: if (CommandInput == "uptime"): print(y, "minutes") y = y + 1 time.sleep(1) uptime(9)
I wanted to make some sort of "background timer" that kept running from when the script was executed up to when it was closed, and if I typed a certain line in the input it would show the current number it is in. The problem is that it keeps printing the timer forever, for every single number it counts. I wanted to do a one-time thing, where you could wait as much as you want and type the input, which would show the number the timer is in.
To write a script like that you would need to look into a module called asyncio (https://docs.python.org/3/library/asyncio.html), which would allow you to run multiple things at the same time.
Here is a asyncio hello world:
import asyncio async def main(): print('Hello ...') await asyncio.sleep(1) print('... World!') # Python 3.7+ asyncio.run(main())
- How can I print literal curly-brace characters in python string and also use .format on it?
- How to access index in function for applymap in pandas?
- Finding all possible permutations of a given string in python
- Using regex to alter digits pandas
- regaining original line breaks pandas \n
- Error when using two matching foreignKeys in django
- Proper use of method overriding with multiple inheritance?
- Python dynamically define function within function
- Lazy logger message string evaluation
- Add –cleanup option to python3 -m test to remove `test_pyt
- thon 2.7 at https://docs.python.org. If you want to understa
- GI scripts * mod_python * FastCGI and SCGI
- sourceforge.net/projects/python/. The most important of the
- here in the world is www.python.org located? * Why is
- terminal: python setup.py install For W
- rting, you can email the python-porting mailing list with qu
- !/usr/bin/env python -*- coding: UTF-8 -*-
- s set up at https://bugs.python.org. One installation of Rou
- * Changes in ‘python’ Command Behavior