Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'static': 0.04; 'foss': 0.09; 'null,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:while': 0.09; 'api': 0.11; 'python': 0.11; 'invoking': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'seconds.': 0.16; 'size;': 0.16; 'statement.': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; 'received:comcast.net': 0.24; 'cheers,': 0.24; 'script': 0.25; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '----': 0.29; 'am,': 0.29; 'quickly': 0.29; 'skip:( 20': 0.30; 'coded': 0.31; 'fine,': 0.31; 'stuff': 0.32; '-----': 0.33; 'subject:from': 0.34; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'hundreds': 0.35; 'but': 0.35; 'next': 0.36; 'method': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'how': 0.40; 'simple': 0.61; 'taking': 0.65; 'here': 0.66; 'determine': 0.67; 'below.': 0.71 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ned Batchelder Subject: Re: how avoid delay while returning from C-python api? Date: Wed, 28 May 2014 06:57:09 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: c-50-133-228-126.hsd1.ma.comcast.net User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401274647 news.xs4all.nl 2838 [2001:888:2000:d::a6]:49582 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72148 On 5/28/14 6:22 AM, Lakshmipathi.G wrote: > Hi - > > I have C-Python api like below. It works fine, but the problem is > while invoking this method > from python script say > > #cat script.py > > offset=0 > size=4 > write_object(offset,size) > > > > This calls write_this_c() C api and returns quickly to next printf statement. > But the return call (Py_RETURN_NONE) takes something like 4-6 seconds. > > ----- > static > PyMethodDef xyz_methods[] = { > {"write_object", write_object, METH_VARARGS,"write some stuff "}, > {NULL, NULL, 0, NULL} > }; > > > ---- > static PyObject * > write_object(PyObject *self, PyObject *args) > { > int offset, size; > if (!PyArg_ParseTuple(args,"ii", &offset, &size)) > Py_RETURN_NONE; > > printf("before call"); > write_this_c(offset, size); > printf("after call"); > Py_RETURN_NONE; ##delay happens here > } > > How to avoid this delay time? Thanks for any help/pointers! It can't be as simple as the Py_RETURN_NONE taking 4-6 seconds: hundreds of built-in functions in Python are coded exactly this way, and they don't have a delay on return. Something else is going on. How did you determine that it was the return that was taking the time? > > > ---- > ---- > Cheers, > Lakshmipathi.G > FOSS Programmer. > www.giis.co.in > -- Ned Batchelder, http://nedbatchelder.com