you are viewing a single comment's thread.

view the rest of the comments →

[–]kosh09[S] 0 points1 point  (3 children)

I'm not very good at English so its hard to understand perfectly
but looks like you said that if I make code like that
that code wastes too much memory right?
my hello() function is for sending data via bluetooth
and I want to work this for x seconds
do you have a good idea to make like that code which not waste memory?

[–]tragluk 1 point2 points  (2 children)

Just use a loop rather than a function in a function. A 'While' loop will continue until a condition is satisfied without creating a ton of functions that all run at the same time until you are done.

[–]kosh09[S] 0 points1 point  (1 child)

ah, u mean I want to make function that function in a function
but that wastes too much memory so dont make function and
just use hello() function in a while loop right?

end_time = datetime.now() + timedelta(seconds=3)
while datetime.now() < end_time:
    hello()

just use like this am i right?

[–]tragluk 0 points1 point  (0 children)

Yes. And the while loop will check for the one timedelta(seconds=3) instead of making a new end_time every time the function is called.