Looking for some help with a user c module for the unix port #14316
Replies: 7 comments
-
You're passing |
Beta Was this translation helpful? Give feedback.
-
I actually figured out what the problem was last night. I am not able to enter Python code from a thread that was not started in Python code. I am sure there is some way it can be done, I couldn't figure out how to do it. The user c module I wrote has things that need to move between Python and C code. I was using SDL to create 2 threads, one was to handle writing frame buffer to SDL. This is a double buffering design and there is a flag that gets set to inform the graphics framework when a frame buffer has been written. It does this to let the frame work know it can write to the buffer. The second thread was to poll for events. because those threads were started in C code and they are running in C code I am not able to make the jump from C code to Python code by calling a user supplied callback. IDK I have tried scheduling the callback to be called from the main thread and that doesn't seem to work either even after specifically telling MicroPython to run any scheduled tasks. It doesn't work. I am am sure it can be done, I have not been able to locate any code I could use as an example for doing this. |
Beta Was this translation helpful? Give feedback.
-
I actually have applications which run multiple threads, one of them running MicroPython, and IIRC the key thing to get this working was setting |
Beta Was this translation helpful? Give feedback.
-
MICROPY_STACK_CHECK is not defined for the unix port so that has no bearing because it not being defined is the same as it being a zero. I get the segfault when mp_call_function_n_kw is called from inside of a thread that was started inside of C code. I am not able to call a python function from a thread that was created in C code. If I create the thread in python code then call a C function that ends up calling the python callback then it works. I have also tried using mp_sched_schedule to have the function called via the main thread and that still results in a segfault. I have to mess about with it some more to see if I can get it to work the way that I want. I have changed so many things to get it to work so I may but the thread code back the way I had originally had it and see if it will run. If it does then IDK what the issue would have been. LOL |
Beta Was this translation helpful? Give feedback.
-
You sure about that? The standard variant has Again, threading itself is not really an issue, but there are some things you should take care of. |
Beta Was this translation helpful? Give feedback.
-
You have this defined in py/mpconfig.h #ifndef MICROPY_STACK_CHECK
#define MICROPY_STACK_CHECK (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES)
#endif you have this define in py/mpconfig.h #define MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES (MICROPY_CONFIG_ROM_LEVEL >= MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES) there is this in py/mpconfig.h #define MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES (30) you have this defined in ports/unix/mpconfigport.h #ifndef MICROPY_CONFIG_ROM_LEVEL
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES)
#endif you have this defined in py/mpconfig.h #define MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES (10) This is some nested stuff right here. This is what you end up with #define MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES (10)
#define MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES (30)
#ifndef MICROPY_CONFIG_ROM_LEVEL
#define MICROPY_CONFIG_ROM_LEVEL (10)
#endif
#define MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES (10 >= 30)
#ifndef MICROPY_STACK_CHECK
#define MICROPY_STACK_CHECK (10 >= 30)
#endif I was correct in that If I have traced through the macros correctly you wopuld be incorrect about the stack check being enabled. From what I am able to tell it is disabled by default. Now the thing is you mentioned not accessing the interpreter by more than one thread at a time. How would someone go about controlling that? The main thread is going to be continually. The whole purpose to what I am trying to do is to collect events for things like mouse movements and window resizing at the moment they actually take place. I need to be able to push those events into the main the GUI is able to be updated. I know there is I believe where I am running into an issue with the segfault is because of the call to maybe I need to have a while loop to check the number of pending tasks to ensure that it is a zero after I schedule the task. I would need to use I still haven't figured out why the stack comes into play with this. I need to get the data pushed into the main thread and I am unsure if calling |
Beta Was this translation helpful? Give feedback.
-
I changed the code and did as you said and the segfault still happens. It seems to be happening when I create the list to store the data that is to be passed to the scheduler. I am going to attempt to just have the scheduler call the callback passing None as the argument. lets see if that will work. |
Beta Was this translation helpful? Give feedback.
-
I keep on getting a segfault and for the life of me I don't know why it is happening.
It is occurring on line 565 of the attached file below
sdl_bus.c.txt
maybe someone can shed some light as to why this is not working. Would a method being passed as the callback instead of a function cause that kind of an issue?
The same kind of code is used to pass arguments to a callback function in other places in Micropython code. I added passing
self
just to see if that would fix the problem thinking that the problem might be because of using a method as a callback. That is not the case.Any assistance on this would be really helpful. I am starting to go bald from pulling my hair out.
Beta Was this translation helpful? Give feedback.
All reactions