Multithreading

Yigit Turgut y.turgut at gmail.com
Mon Dec 26 15:13:01 EST 2011


On Dec 26, 10:03 pm, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> On Mon, Dec 26, 2011 at 1:01 PM, Ian Kelly <ian.g.ke... at gmail.com> wrote:
> > You essentially have two completely independent loops that need to run
> > simultaneously with different timings.  Sounds like a good case for
> > multiple threads (or processes if you prefer, but these aren:
>
> I accidentally sent before I was finished.  I was saying "or processes
> if you prefer, but these aren't CPU-bound, so why complicate things?"
>
> Cheers,
> Ian

I had thought the same workaround but unfortunately loop is already
under a def ;

def writeWaveform(self, fo, header=''):
        data1 = numpy.zeros(self.size)
        screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        timer = pygame.time.Clock()
        white = True
        fo.write(header)
        start = time.time()
        end = time.time() - start
        while(end<10):
	  data1 = self.chan1.getWaveform()
	  end = time.time() - start
	  timer.tick(10) #FPS
	  screen.fill((255,255,255) if white else(0,0,0))
	  white = not white
	  pygame.display.update()
	  for i in range(self.size):
	      end = time.time() - start
	      f.write("%3.8f\t%f\n"%(end,data1[i]))



More information about the Python-list mailing list