Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72148
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Subject | Re: how avoid delay while returning from C-python api? |
| Date | 2014-05-28 06:57 -0400 |
| References | <CAKuJGC8rrXjPWQs3xZMNmyBMkx2ko361Pnx0xuJ4SwRjvj_e-A@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10386.1401274647.18130.python-list@python.org> (permalink) |
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
> <snip>
> offset=0
> size=4
> write_object(offset,size)
> </snip>
>
>
> 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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: how avoid delay while returning from C-python api? Ned Batchelder <ned@nedbatchelder.com> - 2014-05-28 06:57 -0400
csiph-web