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


Groups > comp.lang.python > #29392

Re: Using Py_AddPendingCall

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'handler': 0.04; 'interpreter': 0.04; 'python': 0.09; '"if': 0.09; 'arg': 0.09; 'called.': 0.09; 'doing?': 0.09; 'func': 0.09; 'happens.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runs,': 0.09; 'thread': 0.11; '*should*': 0.16; 'all?': 0.16; 'assigns': 0.16; 'from:addr:pitrou.net': 0.16; 'from:addr:solipsis': 0.16; 'from:name:antoine pitrou': 0.16; 'invoked.': 0.16; 'loops': 0.16; 'manner,': 0.16; 'message-id:@post.gmane.org': 0.16; 'pthread': 0.16; 'received:213.41.240': 0.16; 'received:213.41.240.54': 0.16; 'received:80.91.229.3': 0.16; 'received:charlus.yi.org': 0.16; 'received:plane.gmane.org': 0.16; 'received:yi.org': 0.16; 'thread.': 0.16; 'wording': 0.16; 'successful,': 0.17; 'url:dev': 0.17; 'pending': 0.20; 'header:User-Agent:1': 0.26; 'timely': 0.27; 'header:X-Complaints-To:1': 0.28; 'earliest': 0.29; 'question:': 0.29; 'writes:': 0.29; 'yields': 0.29; 'function': 0.30; 'code': 0.31; 'url:python': 0.32; '(2)': 0.32; 'switch': 0.32; 'running': 0.32; 'function.': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; '(1)': 0.34; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'charset:us-ascii': 0.36; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'necessarily': 0.63; 'soon': 0.70; 'subjectcharset:utf-8': 0.72; 'antoine.': 0.84; 'subject:Using': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Antoine Pitrou <solipsis@pitrou.net>
Subject Re: Using Py_AddPendingCall
Date Mon, 17 Sep 2012 22:42:20 +0000 (UTC)
References <fe3c43a2-9a77-4db2-8836-e15310a6d078@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host sea.gmane.org
User-Agent Loom/3.14 (http://gmane.org/)
X-Loom-IP 213.41.240.54 (Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.843.1347921765.27098.python-list@python.org> (permalink)
Lines 29
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347921765 news.xs4all.nl 6882 [2001:888:2000:d::a6]:59721
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:29392

Show key headers only | View raw


css322 <charles.salvia316 <at> gmail.com> writes:
> 
> (1) A worker thread calls Py_AddPendingCall and assigns a handler function.
> (2) When the Python interpreter runs, it calls the handler function whenever
it yields control to another thread

Not exactly. As the documentation says: "If successful, func will be called 
with the argument arg *at the earliest convenience*."
This is a deliberately vague wording to stress that the function will not be
called as early as you think. It *should* be called in a timely manner, but not
necessarily as soon as the thread switch happens.

Which begs the question:

> In this example, worker_thread is invoked in C as a pthread worker thread. This
> loops infinitely, but the pending call handler is never invoked.

What is your main Python thread doing? Is it running Python code (*)? Or do you
have a main Python thread at all? The "main Python thread" is the one from which
Py_Initialize() was called.

(*) for example, running one of the following functions:
http://docs.python.org/dev/c-api/veryhigh.html

Regards

Antoine.

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


Thread

Using Py_AddPendingCall css322 <charles.salvia316@gmail.com> - 2012-09-16 10:08 -0700
  Re: Using Py_AddPendingCall Antoine Pitrou <solipsis@pitrou.net> - 2012-09-17 22:42 +0000

csiph-web