[Python.NET] Fwd: Tips for Debugging?

Alex Catarino alex at quantconnect.com
Fri Jul 27 15:28:31 EDT 2018


Hi pythonnet team,

I followed your tutorials ( https://github.com/pythonnet/
pythonnet/wiki/Various-debugging-scenarios-of-embedded-CPython) and I could
test two out of three scenarios (I couldn't get ptvsd to work).
When I tested it on Lean, I've verified that we don't get much information
with the mixed-mode cross-language debugger, so I extended your example
with a mock Lean algorithm:
https://github.com/QuantConnect/pythonnet/tree/debug

First scenario - mixed-mode cross-language debugger (attached file:
mixeddebugger.png):
The debugger doesn't give us the information about the object if we
click/mounse over on it or inspect it in Locals/Watch. We need to know what
attributes it has to access them in "Immediate Window".

Second scenario - python debugger  (attached file: pythondebugger.png):
The debugger does show the information.

The issue with the python debugger is that as we are using threads in Lean,
we need to detach and reattach on every iteration in this code snippet the
emulates the OnData call:

            Task.Factory.StartNew(() =>
            {
                algorithm.Run();

            }).ContinueWith((ant) =>
            {
                algorithm.Initialize();

            }).ContinueWith((ant) =>
            {
                algorithm.OnData(DateTime.UtcNow.ToString());
                algorithm.OnData(DateTime.UtcNow.ToString());
                algorithm.OnData(DateTime.UtcNow.ToString());

            }).Wait();

I have tried to attach the debugger in different places in the python
script. If I call it in module level, breakpoints are never hit in the
algorithm. If I call it in Initialize, only breakpoints in Initialize are
hit. And finally, if I call it in OnData, I need to detach and reattach on
every OnData call from the block above.

Best regards,
Alex


On Wed, Jul 25, 2018 at 12:13 AM, Denis Akhiyarov <denis.akhiyarov at gmail.com
> wrote:

> I wrote a debugging tutorial using PTVS here and further improvements are
> welcome!
>
> https://github.com/pythonnet/pythonnet/wiki/Various-debuggin
> g-scenarios-of-embedded-CPython
>
>
> On Tue, Jul 10, 2018, 2:13 AM Jared Broad via PythonDotNet <
> pythondotnet at python.org> wrote:
>
>> Hello PythonNet
>>
>> Do you have any tips/experiences/tools for allowing debugging for a
>> C#-pythonnet script?
>>
>> Thank you
>> Jared
>>
>> --
>> Jared Broad
>>
>> www.quantconnect.com
>> Phone-USA: +1 917 327 0556
>> *Democratizing Finance, Empowering Individuals*
>> Facebook <http://www.facebook.com/QuantConnect> | Twitter
>> <https://twitter.com/#!/QuantConnect> | LinkedIn
>> <http://www.linkedin.com/company/quantconnect> | Skype: jaredbroad
>>
>> We're recruiting! Join us and make your mark on the future of finance
>> <https://www.quantconnect.com/jobs>
>> _________________________________________________
>> Python.NET mailing list - PythonDotNet at python.org
>> https://mail.python.org/mailman/listinfo/pythondotnet
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20180727/8bf5d311/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mixeddebugger.PNG
Type: image/png
Size: 35463 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20180727/8bf5d311/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pythondebugger.PNG
Type: image/png
Size: 60462 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/pythondotnet/attachments/20180727/8bf5d311/attachment-0003.png>


More information about the PythonDotNet mailing list