Suicide Bunny
Suicide Bunny

Reputation: 928

how to run periodic task in high frequency in flask?

I want my flask APP to pull updates from a local txt file every 200ms, is it possible to do that?

P.S. I've considered BackgroundScheduler() from apschedulerler, but the granularity of is 1s.

Upvotes: 0

Views: 781

Answers (2)

Whatever you put inside the function will be dealt for every 200ms.

import datetime, threading

def foo():
    print datetime.datetime.now()
    threading.Timer(0.2, foo).start()

foo()

Upvotes: 2

Alex Grönholm
Alex Grönholm

Reputation: 5901

Couldn't you just start a loop in a thread that sleeps for 200 ms before the next iteration?

Upvotes: 1

Related Questions