[Tutor] real time response

Alan Gauld alan.gauld at yahoo.co.uk
Wed May 24 04:30:20 EDT 2017


On 23/05/17 21:07, Michael C wrote:

> def do_stuff:
>      blah
>      check()
>      blah
>      check()
>      blah
>      check()
>      blah
> 
> and then either break or return if condition is met?
> 
> But that just isn't responsive enough. Is there a way to make function
> check for the  event every 0.5 seconds without interfering with the
> do_stuff, ie a code that has its' own space?

Yes. What you have just described is called threading. You can
start a separate sub-process running in the background to
"do stuff" while in your main program (thread) you can monitor
the dots. If your condition is met you can close the sub-thread.

Threading is non trivial however and very easy to get wrong.
I suggest you google for some tutorials and maybe watch a
Youtube video or two to get a feel for it.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list