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


Groups > comp.lang.python > #102699 > unrolled thread

Re: Help using Thread (or other method)

Started byChris Angelico <rosuav@gmail.com>
First post2016-02-09 11:17 +1100
Last post2016-02-09 11:17 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Help using Thread (or other method) Chris Angelico <rosuav@gmail.com> - 2016-02-09 11:17 +1100

#102699 — Re: Help using Thread (or other method)

FromChris Angelico <rosuav@gmail.com>
Date2016-02-09 11:17 +1100
SubjectRe: Help using Thread (or other method)
Message-ID<mailman.116.1454977078.2317.python-list@python.org>
On Tue, Feb 9, 2016 at 7:59 AM, Brendan Simon (eTRIX)
<brendan.simon@etrix.com.au> wrote:
> My application mainloop (not the threads) needs to be high priority and
> always process as soon as it gets an interrupt.  Is using select a good
> way of doing this?  How can I ensure that no other threads are utilizing
> the CPU, etc?  I'm worried about the GIL (I'm using CPython 2.7).
>

First and foremost, don't worry about the GIL. It's almost never a
problem, so wait until you have proof of its guilt before you start
trying to fire it. In your situation, your quoted problem is that HTTP
requests take time - in other words, that your code is blocking - so
nothing's going to be spinning in the CPU.

The most obvious solutions to your initial problem are (1) threads,
and (2) async I/O. If there's only one part of your code that's ever
at risk of problematic blocking, you might be able to do that part
asynchronously and most of the rest of the code with simple blocking
calls; what that'd mean is that you won't process HTTP responses until
your code next "falls idle" in its primary loop (waiting for another
interrupt), which is pretty much what you'd have with any other scheme
anyway. You could look into a Python 3.5 async/await model, using a
library like this (never used it, just found it on Google):

https://github.com/KeepSafe/aiohttp

Otherwise, threads are great.

ChrisA

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web