[f2py] Python callback recursively calling extension module

Peter Wang pwang at enthought.com
Fri Oct 28 22:11:34 EEST 2005


Hi,

I'm trying to call an extension module wrapped with f2py from a Python 
function that is itself being called by the same module:

import callback
def func2(j):
     return j-2
def func1(i):
     return callback.foo(func2) + i

print "calling func() alone:", func1(10)
print "calling via recursive callback:", callback.foo(func1)

"callback" is the example fortran module described in the f2py docs:
http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#call-back-arguments

This leads to an odd error:

calling func alone: -12.0
calling via recursive callback:capi_return is NULL
Call-back cb_fun_in_foo__user__routines failed.

Traceback (most recent call last):
   File "recursetest.py", line 12, in ?
     print "calling via recursive callback:", callback.foo(func1)
   File "recursetest.py", line 8, in func1
     return callback.foo(func2) + i
TypeError: foo argument fun must be callable

I've also tried defining func2 as a nested function inside func1, but that 
fails with the same error.

Can someone give me a clue as to what's happening?


Thanks,
Peter



More information about the f2py-users mailing list