How to Debug python package command line arguments - visual-studio

I have a python package installed on my machine. I could interface with it via the command line. How could I enter my debugger to see the "Call Stack" of the currently running processes that were executed by me from the terminal. Example, running "packagex command --argument" executes a process, I want to see what is happening with this call.
I'm not certain of what to try because the following searches didn't reveal what I am trying to do.
debug a command called from a terminal vscode
debugging an entire package vscode
debug client process vscode
...
It may be that I'm not searching for the correct thing which is why I'm not finding an answer.

Related

Connect Debugger to NPM shell script that runs other repos, in VSCODE

I am using VSCODE on mac and trying to run a debugger to stop at breakpoints, when running an NPM script.
The NPM script is a shell script (.sh) and it starts a "watcher" on 4 different repos, that form my local server for the project.
The issue is that when I run the debugger on the relevant NPM script (using vscode's 'debug script' option), it seems like VSCODE has a debugger attached, but it never stops at my breakpoints.
The server itself seems to work fine.
I read a lot of answers regarding debugging NPM scripts, but they always refer to a .js file.
Am I not connecting the debugger in the correct way?
Is it possible to debug a shell script that runs this way?
My guess is that the debugger is only connected to the shell script which works fine, but "doesn't know" about the breakpoints in the actual repos that are launched with the script.
Would appreciate any help.
Thank you.

Installing Windows Service fails when command run in batch file

I'm converting a legacy VC 6 C++ Windows Service application to Visual Studio 2022
The conversion is completed and, if I open a CMD prompt with Admin rights, I can install the service using this command:
Service.exe /Install
It installs instantly and starts correctly.
However, I need to install it within an installation script, which loads a bunch of services by calling a batch file which contains the commands to start them. It is run with elevated permissions. However, which it reaches the above line (Service.exe /Install) it hangs. There is no error message and I cannot even terminate it using CTRL + C. The only way around it is to close the CMD prompt. The service is not installed.
My service does not appear in the Task manager's list of processes when the batch file hangs.
I've tried adding the full path to the service in the batch file but it makes no difference. Running this batch file from an elevated command prompt (rather than the installer script) runs into the same problem.
I'm tearing my hair out over this (almost bald now :-)) - can anyone provide any suggestions?
Thanks
Andy
Debugging found a logic error in the start up code.
Basically, calling Service.exe /Install directly from the command line just passes "Service.exe /Install" as the command line, whereas calling it from a batch file / CreateProcess() passes the whole path to the service in the command line and the parser was not taking that into account. Maybe it behaved differently in older Windows versions, but the parser was really badly written.
I'm glad it was me who wrote it :-)

rustc disappears when executing cargo run on windows

I am curently developing a Rust program on Windows 10. A few months ago I created a library package using cargo. Since then, I've been developing this program. Whenever I want to execute what I have, I goto to cmd and execute the following command inside my cargo folder:
cargo run --release --bin main
But, a few weeks ago something strange started to happen. Whenever I execute this same command, I notice that the program in fact starts but it finishes preemptively (I know this because of the output to the terminal). When the program finishes it is supposed to write to the terminal "FINISHED". But this never happens. If I execute the command again (without changing the code), this time the only thing that's printed to the terminal is the build message that cargo puts out. Then, when I execute a third time, I have the following message on my terminal:
error: 'cargo.exe' is not installed for the toolchain 'stable-x86_64-pc-windows-msvc'
To install, run `rustup component add cargo --toolchain stable-x86_64-pc-windows-msvc`
Then if I execute the suggested command, I have the following:
component 'cargo' for target 'x86_64-pc-windows-msvc' was automatically added because it is required for toolchain 'stable-x86_64-pc-windows-msvc'
What's weird is that if I execute the previous cargo run command on the Ubuntu terminal application that I have (it simulates a linux terminal, but I am still on my windows file system), this problem doesn't occur. I can execute 100 or 1000 times and no problems. But this isn't good, since my program creates a multi threaded environment and my Ubuntu terminal is like a virtual machine, so I don't believe that I have access to all of my laptop's memory.
Currently I have the following version of rust on windows and my ubuntu terminal:
rustup 1.18.3 (435397f48 2019-05-22)
What I have been doing until now to solve this is on my windows is to reboot my computer and reinstall rust, since when I execute "rustup self uninstall" sometimes an error of not having permissions to install it appears (I only have 1 user on my pc and supposedly I have admin privileges).
I have googled this situation, but I haven't found anything regarding rustc disappearing when executing cargo run. Now I can't even run my program on windows cmd, since this problems happens every time.
The problem was the anti virus I had on my PC.
After replacing it the program is working perfectly and finishing without the problem I had with rustc.

How to debug code running from terminal in pycharm

I am running my code in Pycharm from Terminal. Is it possible to debug the code and put breakpoints inside the code during a run from terminal?
I don't know anyway to do this through the terminal, but the way I currently do it is:
Run > Edit Configurations > Add new configuration (the green + button)
Choose Python
Fill out Script path, Parameters, and other configuration fields.
Debug the newly added configuration. (Run > Debug...)
With the right configuration the result should be the same as running the script in a terminal.
I find the above process a little tedious. A PEP 553 breakpoint() might be nicer. It requires Python 3.7 and is not implemented yet. See the related issue.
Even if the program is started outside of PyCharm, we can attach PyCharm debugger to it.
Go to Run -> Attach to process.
This will show a list of python process that are currently running on the system. Select the appropriate process from it.
Now PyCharm debugger is connected to that process. We can add breakpoints and debug it.
There is a way using python console.
To run it: Tools -> python console .. or you can find it at the bottom of the IDE.
Then press on 'Attach debugger' line in the following picture:
Add a breakpoint in your code and then pass the file name to the cosole, like: %run my_file.py

Pycharm: MultipleInstanceError: Multiple incompatible subclass instances of PyDevTerminalInteractiveShell are being created

In PyCharm, if I run a script in debug mode (with debug console on), then stop at a breakpoint, and try to type something into the console, I get:
MultipleInstanceError: Multiple incompatible subclass instances of PyDevTerminalInteractiveShell are being created.
Does anybody know what might be causing this and how to fix it?
For me, I had this issue when using ipdb in another terminal from the same code. I had ipdb present in file A, and a terminal with an ipython shell open running this code. I commented out the ipdb bits from file A and ran the debugger in pycharm and this error started up. When I closed the shell I had open in my terminal the error went away.

Resources