function that stop the script in python like stop() in R - python

I am writing a script in python and I would like to stop the scipt in the middle to see the objects and things. I used sys.exit() in pyscripter and everything is fine, but when I switch to spyder, the python interpreter is killed and I cannot read anything after the script is stopped.
How to fix it?

Related

How do I debug through a gdb helper script written in python?

there may very well be an answer to this question, but it's really hard to google for.
you can add commands to gdb by writing them in python. I am interested in debugging one of those python scripts that's running in gdb session.
my best guess is to run gdb on gdb and execute the user added command and somehow magically break on the python program code?
has anybody done anything like this before? I don't know the mechanism by which gdb calls python code, so if it's not in the same process space as the gdb that's calling it, I don't see how I'd be able to set breakpoints in the python program.
or do I somehow get pdb to run in gdb? I guess I can put pdb.set_trace() in the python program, but here's the extra catch: I'd like to be able to do all this from vscode.
so I guess my question is: what order of what things do I need to run to be able to vscode debug a python script that was initiated by gdb?
anybody have any idea?
thanks.
so I figured it out. it's kinda neat.
you run gdb to debug your program as normal, then in another window you attach to a running python program.
in this case the running python program is the gdb process.
once you attach, you can set breakpoints in the python program, and then when you run commands in the first window where the gdb session is, if it hits a breakpoint in the python code, it will pop up in the second window.
the tipoff was that when you run gdb there does not appear to be any other python process that's a child of gdb or related anywhere, so I figured gdb must dynamically link to some python library so that the python compiler/interpreter must be running in the gdb process space, so I figured I'd try attaching to that, and it worked.

Creating a super basic Shell

I've been messing around with os.system and subprocess.Popen in a while loop that printed the output and took input(">") and ran into an issue whenever I tried something like running notepad. It would hang until I closed the gui application. It also doesn't let me cd which is probably because the process ends the moment the command is done.
What I'm basically asking is if there is a way to run your terminal/command prompt with all it's functionalities within a python console application?

Restarting Python Script

I would like to know if any python script is terminated in the middle due to powerloss or some other stuff,Can the python script be restarted where it left?.
Is it possible anyhow that the script restarts from only where the code has not been executed.
THANKS.

Stop Python from Opening Interactive Console on Script Quit?

I've had an issue, more of a nuisance, with python 3.6 specifically that I cant find an answer to after searching for it, and thinking I would be clever by looking for a python config file.
Whenever I run a script and that script quits, my command line pops open with an interactive console for that script, even though I've added exit(); quit() and tried just quit() to my script. I don't want to be forced to type quit() into the CLI every time I run my script. Is there a way to disable this functionality of Python?

How does one kill a python script without killing iPython?

I wrote a script in python with a wx.Frame, and it has an exit function that calls sys.exit() when the user has clicked the close button. I'd like to be able to run this script from iPython, but when the user clicks the close button, sys.exit() kills the running python script as well as iPython. What could I use in place of sys.exit() to kill only the python script, not iPython?
Thanks!
I am not familiar with iPython but with a little searching I found a page:
http://ipython.scipy.org/moin/InterupptingThreads, I infer from this that all you might have to do is "raise SystemExit".

Categories

Resources