-1

How would I go about prompting user-input, while at the same time running timers, to periodically execute automatic functions.

Pseudo-code to illustrate:

while true 
{
    if input() OR timer(10)
    {
        if input() != Nill
        { 
            execute input.value
        }
        else 
        {
            execute automatic/periodic functions
        }
    }
}

So basically it executes functions every 10 seconds, but gives the possibility to enter commands at the same time, without interrupting the timer. I would have to use threading to lock the processes while user-commands are being executed, so I don't get errors from automatic processes interrupting executions.

0

Either use multiple threads that run concurrently, or use an event loop. In an event loop, both user input and the timer would be an event. When it is triggered, your code is executed. Python's asyncio module provides an event loop in the standard library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.