Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault ( Pycall [BUG] Segmentation fault at 0x0000000000000010 ) #183

Closed
mAreebAlam opened this issue Jul 25, 2024 · 4 comments

Comments

@mAreebAlam
Copy link

there is problem in the method import_module of file "pycall-1.5.2/lib/pycall.rb"

def import_module(name)
LibPython::Helpers.import_module(name)
end

it calls a c method in this file "ext/pycall/pycall.c"

C language method

static VALUE
pycall_libpython_helpers_m_import_module(int argc, VALUE *argv, VALUE mod)
{
VALUE name, globals, locals, fromlist, level;
char const *name_cstr;

rb_scan_args(argc, argv, "14", &name, &globals, &locals, &fromlist, &level);

if (RB_TYPE_P(name, T_SYMBOL)) {
name = rb_sym_to_s(name);
}

name_cstr = StringValueCStr(name);

if (argc == 1) {
return pycall_import_module(name_cstr);
}

if (argc == 5) {
level = rb_check_to_integer(level, "to_int");
}
else {
/* TODO: set the default level to 0 */
}

return pycall_import_module_level(name_cstr, globals, locals, fromlist, NUM2INT(level));
}

which again calls the previous method and the process continues in an infinite loop, hence segmentation fault occurs

@snickell
Copy link

snickell commented Aug 8, 2024

I don't think there is a loop here, I have traced the code like this, I do not see any loops:

  • LibPython::Helpers.import_module(name)
    • calls rb_define_module_function(mHelpers, "import_module", pycall_libpython_helpers_m_import_module, -1);
      • calls pycall_libpython_helpers_m_import_module
        • calls pycall_import_module
          • calls libpython: Py_API(PyImport_ImportModule): NO LOOP
        • calls pycall_import_module_level
          • calls Py_API(PyImport_ImportModuleLevel): NO LOOP

Are you using Rails or Puma? If so, PyCall is NOT safe to call from a web request, even if puma/rails has threads set to 1. Do you have threads in your application?

I suspect this might be the same issue as:

@snickell
Copy link

snickell commented Aug 8, 2024

See: "is pycall thread safe": #96

@mAreebAlam
Copy link
Author

Thanks for clarification
I think you are right, the issue is due to puma

@snickell
Copy link

snickell commented Aug 8, 2024

@mAreebAlam I'm working on an approach for working with Puma, let me know if you want me to ping you when its working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants