i have googled around for python timed infinite loops, but didnt find anything useful.
For example, i want to perform a certain function at certain timed intervals, meanwhile the main loop is running.
I know that in programming microchip, you have this interrupt function to use... i mean, the main loop will be exited when certain interrupt flag is triggered.
But how do i do this in python ?!
infinite time loop
Post a Reply
|Oldest Newest Rating|
· February 13, 2015
So, i tried the threading module, and it works fine. Thanks Nishant Kumar Thakur !
I honestly thought this was going to be heavy programming with this module, just to get an interrupt. Though, its still not an interrupt (at least not yet), but a thread that does stuff in timed events, which is very ok for what i need for now. (i need to check for interrupt data on the mcu, checking certain bytes for events)
I will also implement this in some kind of status bar... if there isnt some better ways of handling refresh/updates of status bars ?!
Just to throw it out here. There is also a neat python tutorial site, which brings up all basic stuffs within python:
Very much thanks !
Nishant Kumar Thakur
· February 9, 2015
You could do it using multithreading in python, where a thread would be triggered at regular time intervals.
if the functions that need to be regularly triggered and main loop are mostly unrelated (eg. share no common variable etc.), you could have those functions in a different file than main loop so that you could run both scripts in different command prompts simultaneously (a hackish way of using threads).
· February 9, 2015
Hmm, yes, i read about the multithreading... i guess i will have to look into that.
But there must be some way of fetching/calling a function in the mainloop ? I read something about timers, and setting of functions with that.
As my code will interface with an microchip quite much, at the moment, the python code pretty much sits and waits for microchip to be finished. In this case, i must look for a certain routine to be finished in the mcu(microchip unit), then the mcu will send some data to the python. However, i must find a way for python to fetch that data, whenever it is finished. Pretty much like the mcu interrupt routines.
So, im looking for an interrupt in python from the main routine. From that interrupt i can always call functions i need.
Multithreading seems to me, equal to have several mcu:s doing various routines at the same time (which is neat), within python offcourse.
Thanks for the reply Nishant !
This section is all about snakes! Just kidding.
|Bucky Roberts Administrator|