Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98045

Re: Multithreading python,two tkinter windows

From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Multithreading python,two tkinter windows
Date 2015-11-02 01:31 +1100
Message-ID <mailman.23.1446388298.4463.python-list@python.org> (permalink)
References <271f8b42-da03-40fd-8a8b-c562292577e6@googlegroups.com>

Show all headers | View raw


On Mon, Nov 2, 2015 at 1:05 AM, Vindhyachal Takniki
<vindhyachal.takniki@gmail.com> wrote:
> #get reading at every 1 second
> def get_analog_1(thread_name):
>     global read_ok_1, current_time_1,analog_1
>     while True:
>         if((time.time() - current_time_1) > 1):
>             if(0 == read_ok_1):
>                 current_time_1 = time.time();
>                 read_ok_1 = 1;
>                 analog_1 = randint(0,100)

Never do this. It's called a "busy-wait", and not only does it
saturate your Python thread, it also saturates your entire system -
this is going to keep one CPU core permanently busy going "are we
there yet? are we there yet?" about the one-second delay. Instead, use
time.sleep(), which will delay your thread by one second, allowing
other threads to run.

Better still, think about your code in terms of events. Most GUI
libraries these days are built around an event-driven model, and the
notion of "make this event happen 1 second from now" or "10 seconds
from now" is a very common one.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Multithreading python,two tkinter windows Vindhyachal Takniki <vindhyachal.takniki@gmail.com> - 2015-11-01 06:05 -0800
  Re: Multithreading python,two tkinter windows Laura Creighton <lac@openend.se> - 2015-11-01 15:26 +0100
  Re: Multithreading python,two tkinter windows Chris Angelico <rosuav@gmail.com> - 2015-11-02 01:31 +1100
  Re: Multithreading python,two tkinter windows Terry Reedy <tjreedy@udel.edu> - 2015-11-01 18:12 -0500

csiph-web