cffi for embedding (fortran): problem related to threads?

Create issue
Issue #427 new
Former user created an issue

Hi,

I am using cffi to use the python dolfin package (from fenics) within a Fortran program. The python code get stuck at a position shown in the attachment, at "noslip.mark(sub_domains, 0)", if I use python 3.7. The problem disappears if python 3.6 is used instead.

A similar problem has been reported here, which is related to the new TSS API introduced in python 3.7 (https://docs.python.org/3/whatsnew/3.7.html#whatsnew37-pep539):
https://bitbucket.org/fenics-project/dolfin/issues/1035/subdomainmark-hangs-when-called-from The problem was solved by using a new version of pybind, compatible with python 3.7 TSS API.

I assume that cffi plays more or less the same role as pybind. Could my problem be related to a compatibility issue of cffi with python 3.7? I am not sure at all that the problem in on cffi side, it may be due to dolfin.

Thanks,

Thomas

Comments (9)

  1. Armin Rigo

    cffi doesn't use the deprecated PyThread_create_key()&co API, so there is nothing to update to the new API.

    However, handling threads in cffi is delicate and I wouldn't be surprised at all if another detail changed in CPython that now breaks that.

  2. Armin Rigo
    (fenicsproject) root@0c713dc2dee4:~/issue427# gfortran -o test -Wl,-rpath . -L. -lplugin test.f90
    /tmp/ccg6pC0I.o: In function `MAIN__':
    test.f90:(.text+0x6c): undefined reference to `fem'
    collect2: error: ld returned 1 exit status
    
  3. Thomas Jourdan

    I can’t understand what’s going on if python3 builder.py worked smoothly. Was there any problem on python side?

    nm libplugin.so gives the following:

    00000000000050a8 b called.12284
    0000000000002040 t call_gmon_start
    0000000000005060 d _cffi_call_python
    00000000000050c0 b _cffi_embed_startup_lock
    00000000000050a9 b _cffi_embed_startup_lock_ready
    0000000000005100 b _cffi_exports
    0000000000005040 d _cffi_externpy__fem
    0000000000004cc0 d _cffi_globals
    0000000000003180 r _CFFI_PYTHON_STARTUP_CODE
    00000000000026e0 t _cffi_start_and_call_python
    0000000000002280 t _cffi_start_python
    0000000000004c60 d _cffi_type_context
    0000000000005020 d _cffi_types
    0000000000005080 b completed.6881
    0000000000004c48 d __CTOR_END__
    0000000000004c40 d __CTOR_LIST__
                     w __cxa_finalize@@GLIBC_2.2.5
    0000000000002057 t deregister_tm_clones
    000000000000275f t __do_global_ctors_aux
    00000000000020be t __do_global_dtors_aux
    0000000000005000 d __dso_handle
    0000000000004c58 d __DTOR_END__
    0000000000005088 b dtor_idx.6883
    0000000000004c50 d __DTOR_LIST__
    0000000000004ce0 d _DYNAMIC
                     U __errno_location@@GLIBC_2.2.5
    0000000000002140 T fem
    0000000000002784 T _fini
    ...
    

  4. Armin Rigo

    Found the problem: the line gfortran must specify test.f90 before the libraries, not after.

    I think I fixed the bug in 7d1496495e25. At least, I did something invalid according to the API. I don't know why it shows up on CPython 3.7 and not 3.6, but they changed details around here, so well. Now your demo works.

  5. Log in to comment