Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17974
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.018 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'essentially': 0.10; 'am,': 0.12; 'def': 0.13; '(0,': 0.16; '(second': 0.16; '0))': 0.16; 'capturing': 0.16; 'frames': 0.16; 'workaround': 0.16; '\xa0for': 0.16; 'cc:addr:python-list': 0.16; 'mon,': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.20; 'seconds': 0.21; 'dec': 0.22; '(or': 0.22; 'header:In-Reply-To:1': 0.22; 'thus': 0.23; "shouldn't": 0.23; 'cc:2**0': 0.24; 'skip:[ 10': 0.27; 'effect': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.29; 'second': 0.29; 'threads': 0.30; 'skip:\xa0 30': 0.32; 'loop': 0.34; 'received:209.85.212': 0.34; '8bit%:3': 0.34; 'changes.': 0.34; 'something': 0.35; 'file': 0.36; 'thread': 0.37; 'two': 0.37; 'but': 0.37; 'run': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'skip:\xa0 10': 0.39; 'else': 0.39; 'received:209': 0.40; '2011': 0.61; 'effective': 0.61; 'grab': 0.66; '26,': 0.67; 'roughly': 0.67; '11:31': 0.84; 'x):': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=+F1atvLlDznYNO8vLDYNg1WPzVPfZ92jzAQQQBxkyBY=; b=OGmVybwEVOCv68VOZuF/O1xuyB9mW1l4lazZq3mZDlIg8BuTaRLwG9ybmUN9T0HQ7V VyPB8L274EG/1P9KzsBDu+AJLn+uKp2PTWDdJEtM4hXNVnzKoYucUmH4a6zQk1jvurqJ JQDrD2MZdQO0J92kZaPg3l0XP/tV9rV9O/zpg= |
| MIME-Version | 1.0 |
| In-Reply-To | <695ebd75-e0ff-409a-9f9a-8143b78bee0a@d10g2000vbh.googlegroups.com> |
| References | <695ebd75-e0ff-409a-9f9a-8143b78bee0a@d10g2000vbh.googlegroups.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Mon, 26 Dec 2011 13:01:20 -0700 |
| Subject | Re: Multithreading |
| To | Yigit Turgut <y.turgut@gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4106.1324929718.27778.python-list@python.org> (permalink) |
| Lines | 57 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1324929718 news.xs4all.nl 6951 [2001:888:2000:d::a6]:50567 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:17974 |
Show key headers only | View raw
On Mon, Dec 26, 2011 at 11:31 AM, Yigit Turgut <y.turgut@gmail.com> wrote:
> I have a loop as following ;
>
> start = time.time()
> end = time.time() - start
> while(end<N):
> 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]))
>
> Roughly speaking, this loop displays something at 10 frames per second
> and writes data1 to a file with timestamps.
>
> At first loop data1 is grabbed but to grab the second value (second
> loop) it needs to wait for timer.tick to complete. When I change FPS
> value [timer.tick()], capturing period (time interval between loops)
> of data1 also changes. What I need is to run ;
>
> timer.tick(10) #FPS
> screen.fill((255,255,255) if white else(0,0,0))
> white = not white
> pygame.display.update()
>
> for N seconds but this shouldn't effect the interval between loops
> thus I will be able to continuously grab data while displaying
> something at X fps.
>
> What would be an effective workaround for this situation ?
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:
def write_data(self, f, N):
start = time.time()
while self.has_more_data():
data1 = self.chan1.getWaveform()
time.sleep(N)
for i in range(self.size):
end = time.time() - start
f.write("%3.8f\t%f\n" % (end, data[i]))
def write_data_with_display(self, f, N, X):
thread = threading.Thread(target=self.write_data, args=(f, N))
thread.start()
white = False
while thread.is_alive():
timer.tick(X)
screen.fill((255, 255, 255) if white else (0, 0, 0))
white = not white
pygame.display.update()
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Multithreading Yigit Turgut <y.turgut@gmail.com> - 2011-12-26 10:31 -0800
Re: Multithreading Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-26 13:01 -0700
Re: Multithreading Yigit Turgut <y.turgut@gmail.com> - 2011-12-26 15:00 -0800
Re: Multithreading Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-26 13:03 -0700
Re: Multithreading Yigit Turgut <y.turgut@gmail.com> - 2011-12-26 12:13 -0800
Re: Multithreading Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-26 13:39 -0700
csiph-web