Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #88252
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!217.188.199.168.MISMATCH!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed4.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.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'concurrently': 0.07; 'pypi': 0.07; 'subject:two': 0.07; 'builtin': 0.09; 'python': 0.11; 'thread': 0.14; '(either': 0.16; 'background,': 0.16; 'concurrent': 0.16; 'displaying': 0.16; 'loop.': 0.16; 'periods': 0.16; 'suggest?': 0.16; 'wrong).': 0.16; 'wrote:': 0.18; 'module': 0.19; 'import': 0.22; "shouldn't": 0.24; 'tend': 0.24; 'fine': 0.24; 'task': 0.26; 'second': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'skip:p 30': 0.29; 'am,': 0.29; "doesn't": 0.30; 'see,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'run': 0.32; "i'd": 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'hi,': 0.36; 'should': 0.36; 'too': 0.37; 'two': 0.37; 'skip:m 40': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'first': 0.61; 'mar': 0.68; '2015': 0.84; 'suited': 0.93; 'technique': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=U6xZCYOsVxDmL2xUqaIxQ2RpL7d3hCizqtboAWJIcs8=; b=QDBbgOaGU1aIN6solEcISjZKv5RG+lkqlCDJbeU8BJlce0TlFsQZHHabp+ZK3Ibamn L651vOpRjX9wK86IlEjX+aPqqdHIGGw/IOaa/B2KCf2VzeQFqdThauxBXxyUomO23F4X MrB+X8iY7R+m/w/4eZ0ZejVBxKMP55YTrlrNJ87f/yCi8O8vaIzwhDdix9Yu/bn7WdAo r0M7qFvr/4Bi6lXdA73zekYI5cFnbMiNTvhapWqpajRdnwoF2ZGXEIu2ojeqB/94d8KL ojJpfR6WnDRAaFH4jkinWXXT0fun2f6kzUsCVlesFfyXZv8Egx4sdTh1888Xm+f1aJK+ lo2w== |
| X-Received | by 10.68.65.100 with SMTP id w4mr25229378pbs.95.1427620451836; Sun, 29 Mar 2015 02:14:11 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <mf8c4p$71p$1@ger.gmane.org> |
| References | <mf8c4p$71p$1@ger.gmane.org> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Sun, 29 Mar 2015 03:13:31 -0600 |
| Subject | Re: Run two processes in parallel |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.302.1427620460.10327.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1427620460 news.xs4all.nl 2906 [2001:888:2000:d::a6]:49909 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:88252 |
Show key headers only | View raw
On Sun, Mar 29, 2015 at 2:11 AM, Thorsten Kampe
<thorsten@thorstenkampe.de> wrote:
> Hi,
>
> I'd like to run two processes concurrently (either through a builtin
> module or a third-party). One is a "background" task and the other is
> displaying a spinner (for which I already found good packages).
>
> The two processes do not have to communicate with each other; only
> the second should be able to know when the first has terminated. To
> make it clear, this is the pseudo-code:
>
> ```
> import time, PARALLEL, spinner
> process1 = PARALLEL.start(time.sleep(60))
>
> while process1.isrunning
> spinner.update()
> time.sleep(1)
>
> print('done')
> ```
>
> From what I see, Python modules threading and multiprocessing seem
> either not suited for that or to be too complicated (though I don't
> have any experience with these and could be wrong). A search on PyPi
> for parallel, background, and concurrent found too many.
>
> What would you do? Which technique or module would you suggest?
It shouldn't be all that complicated:
import time, multiprocessing, spinner
process1 = multiprocessing.Process(target=time.sleep, args=(60,))
process1.start()
while process1.is_alive():
spinner.update()
time.sleep(1)
# join is called implicitly by is_alive, but
# calling it explicitly is good practice.
process1.join()
print('done')
Threading should also work fine as long as your background thread
doesn't hold the GIL for long periods of time, which would freeze out
your spinner update loop. I would tend to prefer threading over
multiprocessing for this since the spinner thread is not CPU-bound.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Run two processes in parallel Ian Kelly <ian.g.kelly@gmail.com> - 2015-03-29 03:13 -0600
csiph-web