Cython module: kodi crash when using import
#1
Hi guys,
Here again, i successfuly built a module with Cython, thanks to the help recived here, now i have another weird problem, (at lest for me!):
I isolated the problem, so just few lines are enough to reproduce the crash.

Hello.pyx
python:
import xbmc, os

def say_hello_to(name):
xbmc.log(os.getcwd())
return "Hello %s!" % name

plugin.py
python:

# -*- coding: utf-8 -*-

import routing
import logging
import xbmcaddon
import os
from resources.lib import kodiutils
from resources.lib import kodilogging
from xbmcgui import ListItem
from xbmcplugin import addDirectoryItem, endOfDirectory
from resources.lib.hello import say_hello_to

ADDON = xbmcaddon.Addon()
logger = logging.getLogger(ADDON.getAddonInfo('id'))
kodilogging.config()
plugin = routing.Plugin()

@plugin.route('/')
def index():
    cat = say_hello_to("Test1")
    xbmc.log(cat)
    addDirectoryItem(plugin.handle, plugin.url_for(
        show_category, "one"), ListItem(cat), True)
    addDirectoryItem(plugin.handle, plugin.url_for(
        show_category, "two"), ListItem("Category Two"), True)
    endOfDirectory(plugin.handle)


@plugin.route('/category/<category_id>')
def show_category(category_id):
    cat2 = say_hello_to("Test2")
    addDirectoryItem(
        plugin.handle, "", ListItem("Hello category %s!" % cat2))
    endOfDirectory(plugin.handle)

def run():
    plugin.run()

On first run, everything is ok, log shows my cwd and Test1, if i choose somenthing from the index list, kodi crashes.
If i will remove imports from hello.pyx evertyng works as espected, but i would like to import something...

AS always remember, i'm a noob and if you need more information just ask! Thanks
Reply
#2
I'm afraid you are out of luck. Memory corruption issues inside C modules are very hard to debug.
Reply
#3
Hi Roman! Thanks for your reply.
Well, i always supposed, i'm very lucky man! Anyway if it could be useful, i can attach the kodi.log/crashlog

 if you know any way i can try to go further let me know! Thank you
Reply
#4
imho, this is because your cpython interpreter and your compiled .so are linked against different versions of cruntime. i am a big of fan linux, but linux sux on abi compatability. a usefull approach would be to run the same setup on windows, because windows abi is not as diverse as linux (glibc).

another thing came to my mind that when you import a module, it is stored sys.modules array, i experienced that python interpreter inside kodi is not very talented in cleaning the imported modules unlike ended as standalone python interpreter. i am also guessing that cpython in kodi is a thread, however python is normally a process. when kodi ends a cpython thread some cmodules imported could not be unloaded.

to overcome this i had manually improted cmodules with imp module and manually overrided the sys.modules dictionary. and it worked. (however there is still potential memory leak problem potential in long term)

see how i loaded netifaces below
https://github.com/hbiyik/script.module....tifaces.py

and how the module is loaded in abi module below.
https://github.com/hbiyik/script.module....__.py#L122

but still all above said are speculative and not %100 accurate, may be not related to your issue at all, i hope it helps.
Reply
#5
hi @boogiepop!
Well i tried many time with windows without luck, wverything is working on python console but not with kodi!
So after a lot of time spent to understand what was wrong i gave up. I had more luck with C++ and pybind11, so i think i will continue in that way!

Thanks again for your time!
Reply

Logout Mark Read Team Forum Stats Members Help
Cython module: kodi crash when using import0