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


Groups > comp.lang.python > #29392

Re: Using Py_AddPendingCall

From Antoine Pitrou <solipsis@pitrou.net>
Subject Re: Using Py_AddPendingCall
Date 2012-09-17 22:42 +0000
References <fe3c43a2-9a77-4db2-8836-e15310a6d078@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.843.1347921765.27098.python-list@python.org> (permalink)

Show all headers | 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