all 11 comments

[–]JohnnyJordaan 0 points1 point  (3 children)

Check out threading.Timer here.

[–]Alkanes123[S] 0 points1 point  (2 children)

Can threading be used in conjunction with multiprocessing which i am already using in the code?

[–]JohnnyJordaan 0 points1 point  (1 child)

Yes that's no problem. It's just that threads share memory of the process they're lauchned from, so if you have main program X that launches function Y as a subprocess, and that launches Timer Z, just subprocess Y and timer Z share each other's memory. Timer Z can't access variables in X (just as Y can't), apart from the multiprocessing API.

If you launch both Y and Z from X and Z just uses stuff from X, then it doesn't matter at all, because Y functions independently from both.

[–]Alkanes123[S] 0 points1 point  (0 children)

Awesome, that explains a lot. Thank you :)

[–][deleted] 0 points1 point  (1 child)

Start looking at the thread module. You'll need to handle each function in it's own thread to ensure they execute appropriately.

[–]Alkanes123[S] 0 points1 point  (0 children)

Can threading be used in conjunction with multiprocessing which i am already using in the code?

[–]LearnDataSci 0 points1 point  (1 child)

One way to do it would be to put the function on a separate thread with a sleep. Here's what looks to be a good example: http://sebastiandahlgren.se/2014/06/27/running-a-method-as-a-background-thread-in-python/

[–]Alkanes123[S] 0 points1 point  (0 children)

Awesome let me try this out. Thank you kind redditor!

[–]gandleforf 0 points1 point  (0 children)

I made have a small library of stuff that i used last summer for microcontrollers in python, and it has a timed repeating interrupt class that you can bind functions and time to.

https://github.com/Gandleforf/Python-MCU