> On 22 Aug 2020, at 20:53, Eko palypse <ekopaly...@gmail.com> wrote: > > Hello, > > background info first. On windows, python3.8.5 > > A cpp app has an embedded python interpreter which allows to modify/enhance > the cpp app > by providing objects to manipulate the cpp app and callbacks to act on > certain events, > like fileopen, fileclose, updateui ... which are send by the cpp app. > The embedded python interpreter acts more or less like the standard python > REPL. > If you run a script with code like > > def test(i): > print(i*2) > > test(4) > > then the test function is now globally available as long as the cpp app is > alive. > > I've written a debugger based on bdb and encountered a situation which I > haven't found out how to handle correctly yet. > > Let's assume I've registered a callback when something changes in the UI. > In that case an object function gets called which highlights certain aspects > in the UI. > > Now if I run a script via this debugger it works as long as I don't use the > same object function. > If I do use it, then the stack gets corrupted(?).
When the app calls into python does the event loop of the gui block? When you print does that trigger the event loop to run in a nested call back into the cpp? Maybe you need to run python in its own thread and Marshall in and out of the gui main thread with the event loop? Barry > For example it look like this > > stack: > <frame at 0x00000000081AB420, file '...\\bdb.py', line 580, code run>, 580 > <frame at 0x0000000004CDF550, file '<string>', line 1, code <module>>, 1 > <frame at 0x0000000004CD6860, file '...\\test_pydebugger.py', line 8, code > <module>>, 8 > > now if I enter the function which call this object function this gets add > > <frame at 0x0000000004CEB040, file '\\test_pydebugger.py', line 5, code > add_match>, 5 > > I step through the code and suddenly the stack looks like this > > <frame at 0x00000000081AB420, file '...\\bdb.py', line 580, code run>, 580 > <frame at 0x0000000004CDF550, file '<string>', line 1, code <module>>, 1 > <frame at 0x0000000004CD6860, file '...\\test_pydebugger.py', line 8, code > <module>>, 8 > <frame at 0x0000000007396A40, file '...\\EnhanceAnyLexer.py', line 154, code > <lambda>>, 154 > <frame at 0x00000000081B35B0, file '...\\EnhanceAnyLexer.py', line 102, code > paint_it>, 102)] > > EnhanceAnyLexer is neither part of the test_pydebugger script nor part of the > debugger. > It is used to register a callback on the updateui event. > > So the question is, what do I need to read/learn/understand in order to solve > this issue? > Or in other words, how can I debug my script in an isolated environment. > I can't manipulate the __main__.dict as this seems to have general impact on > registered callbacks as well. > Any ideas? > > Thank you > Eren > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list