1

I am running a Jupyter notebook on a remote server. Part of this notebook calls a Cython .pyx file cython_file which contains a c++ function definition called cpp_function and is called from the notebook like this:

from clibs.cython_file import cpp_function

Inside the .pyx file I am calling a c++ header file cpp_file.h like this:

cdef extern from "/home/user/cpp_file.h":

Inside this header file I have the function as defined in cython which, for argument sake, is just a simple logic function.

My issue is this; sometimes when I change the .h c++ file and restart the notebook kernel and re-run the code, nothing changes. It still uses the old version of the .h file. As if it's being cached somewhere.

I have deleted all .pyxbldc and .pyc files before restarting the kernel to no avail.

My .pyxbld file looks like this:

def make_ext(modname, pyxfilename):
    from distutils.extension import Extension
    return Extension(name=modname,
                     sources=[pyxfilename], extra_compile_args=['-fopenmp', '-w'], extra_link_args=['-fopenmp'], language='c++')

Any ideas on how to stop the c++ file from being cached?!

3
  • Running Jupyter and Cython locally, I find that I can force recompilation by deleting Cython's cache. On macOS, the default location appears to be ~/.ipython/cython, so I run rm -rf ~/.ipython/cython every time I change Cython code in my Jupyter notebook. I'm not sure how to extend this solution for your situation, but maybe that'll get you started.
    – wkschwartz
    Jun 18, 2019 at 4:25
  • @wkschwartz Any idea where the cython cache is located in linux, specifically Ubuntu? Jun 27, 2019 at 4:29
  • 1
    @RestInPeace Try /home/<user_name>/.cache/ipython/cython Mar 19, 2021 at 13:31

1 Answer 1

0

This doesn't stop the C++ file from being cached, but you can clear the cache before running the %%cython cell magic.

!rm -rf ~/.cache/ipython/cython
1
  • @shaedrich Please pay attention when reviewing. This is not a link-only answer. It is a poor answer which could do with some additional explanation, but it is an answer nonetheless. Dec 29, 2022 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.