Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved into a class, so multiple frequencies can be created #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ferdinandyb
Copy link

Implementing it as a class rather than a module would allow to define multiple frequencies in parallel threads. The syntax need not change much.

Use case:

from cronus.beat import Beat
import time
import datetime
import threading

def do_some_work():
    beat = Beat()
    beat.set_rate(2)
    while beat.true():
        print (datetime.datetime.now(), "doing work")
        beat.sleep()
        
def do_some_work2():
    beat = Beat()
    beat.set_rate(10)
    while beat.true():
        print (datetime.datetime.now(), "doing work2")
        beat.sleep()
if __name__ == "__main__":

    t1 = threading.Thread(target = do_some_work)
    t2 = threading.Thread(target = do_some_work2)
    t1.start()
    t2.start()
    t1.join()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant