#๐Ÿ”’ Timed program using loops

10 messages ยท Page 1 of 1 (latest)

unkempt wadi
#

Solution 1

some_future_time = any
def main():
    while some_future_time => datetime.datetime.now():
        end()

solution 2

list_of_future timing = [any]

async def main():
    for i in list_of_future_timing:
        if i > datetime.datetime.now():
            end()
        else:
            await asyncio.sleep(i)
            end()

Which one is more preferable?

modern pastureBOT
#

@unkempt wadi

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

atomic vault
#

i mean, you don't have to use asyncio, but it's certainly a good idea to sleep instead of spending an entire CPU core on waiting

#

also, not sure what the list is for in the second solution.

unkempt wadi
#

I'm just waiting until specific timing

#

For example i have scheduled something for 1 hour later then it'll be stored in list

ocean mountain
#

what does end() do?

modern pastureBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.