Recover lost python code from running script? - ipython

I am a bit panicked right now, and I hope someone can help. I spent months writing a python program on Notepad++. The final bugs were finally worked out and the script was launched in ipython via PowerShell. Right when I went to push the save button in Notepad++, the program crashed, and when it recovered, all of the code was missing. It is as if I deleted all of the code and then hit save.
The python code is still running, and it should for several more hours. My question: is there a way to recover the code by interrupting the running script and somehow accessing the code from ipython? It always shows several lines of the code in ipython when the script is broken, and I am hoping I can somehow recover the full code through this.

Try this
If that doesn't work, let it be a lesson to ALWAYS back up your work. Use GitHub

Related

How can I fix Visual Studio Code so that it runs and debugs simple basic scripts (.bas files)? [duplicate]

This question already has answers here:
VBS Script - Need to change msgbox to echo
(3 answers)
Closed 9 months ago.
Background
I'm a tech writer but have dabbled in coding for many years now. For work, I need to test about a hundred different ancient script samples. The samples are stored in our documentation. They are in written in Basic (technically, in Cypress Enable BASIC, but it's essentially very similar if not identical to Basic scripting). I need to test them and fix any that are broken.
I want to set up Visual Studio Code to run these because I love VSC as it has a lot of benefits over the very old and vanilla scripting editor included with our product that I've been using.
My Need
Mainly, I need to be able to copy and paste the code I want to test into VSC into a simple .bas file and then run and test the code inside VSC with code coloring, code running, and a debugger. Intellisense would also be helpful. I can get color coding, but getting it to run and debug isn't working.
What I've Tried and Other Notes
I've already spent hours trying to set something up, but can't figure it out.
I have Windows 10
From something I found online, I've mapped this folder C:\Windows\Microsoft.NET\Framework64\v3.5 to my system's Path Environment Variable. (where <user> is my user name).
I've also tried different vbscript and vba related extensions, but have since uninstalled them as nothing seemed to resolve this very basic (no pun intended) problem.
I've searched various posts online and in this site, but haven't found a solution yet.
I tried enabling Run in Terminal in Code-runner to see if that made any difference.
Something is wrong, as I consistently get errors. For example, with Code Runner extension installed, if I try to run this very simple vbscript to show a test message box...
Sub Main ()
Dim testString
testString = "Meh... Will it work?"
MsgBox testString
End Sub
...I get this result in my VSC Output window:
[Running] cscript //Nologo "d:\Temp\vbscripttest.bas"
[Done] exited with code=0 in 0.174 seconds
I find very little info searching on code=0 error that is useful.
My script is in my d:\temp folder. I don't know if that makes a difference. If I try running the .bas file from the File Explorer window directly by double-clicking on it, nothing happens. Though from the icon style, it appears to be mapped to VBScript.
I gather either Windows or vbcode or both can't find the vbscripting goodness that makes things work, though I thought pointing the path variable to C:\Windows\Microsoft.NET\Framework64\v3.5 would fix that.
After two days of pulling my eyebrows out using our product's internal script editor to test my scripts (my hair has long since gone), I am hankering for some good old fashioned debugging support in my favorite code editor!
What do you recommend I do to get things working? Thank you in advance for your help.
Your sample program is running successfully. In that file there is no code in the code path. VBScript in a top level language (unlike VBA). That means code runs outside of a sub or function.
So insert before the first line Main to call Main. Or lose the Sub ... End Sub for VBScript. In VBA/VB6 you would choose Sub Main as the startup sub in Properties.
While this is not your problem, just to be complete, if you start a script in CScript or WScript using //b command line parameter then message boxes are not displayed. See CScript /?.

VSCode Debugging with Mocha and ESM Breaking in ESM "compiled" File Instead of Original

I've been using the ESM module with VSCode and my Mocha unit tests for a long time now, a couple of years at least. Recently when I launch an individual test file in VSCode and set a breakpoint in the test file, it no longer breaks in the original file, but rather breaks in the "ESM compiled" file. I don't really know how ESM works enough to talk about it very well, but the file is compiled/transpiled/transformed in some way with all the imports converted to non-ESModule code. I'm able to step through, and it continues to step through other files as well, but each new file opened is this newly "ESM compiled" version instead of the original file, like it used to be. I only just noticed this recently. So I decided to install and older version of VSCode and see if it still happened, and it turns out it doesn't. With version 1.45.x it works as usual, but with anything newer, I get all these "ESM compiled" files opening up when I step through code.
Does anyone know why this is happening? Is there any new setting I can set in the newer VSCode versions that would cause this to not happen? It's really more of an annoyance than anything. I can still get my work done, but it's not as streamlined as it used to be. I will probably end up just downgrading permanently until I can find a way to make it not occur in the new version.
So, if anyone has experienced this, or knows of something new in VSCode that would cause this, I'd really appreciate some help. Thanks.

How do I figure out which extension or service is making a VS Code Helper process use 100% CPU?

Every so often the fans on my MacBook Pro start revving up and certain things in VS Code stop working, such as indentation and autocomplete etc.
When this happens I use Alfred App to figure out which process is causing an issue and it's usually one or more of the Code Helper processes launched by VS Code. Sometimes they'll a couple of them using way over 100% of the CPU. I kill the processes and then VS Code prompts me that the extension host has quit and to restart it. Once I do that the extensions start working again as normal. And then the whole thing repeats, just not all the time. For instance I'm writing this message now and Code is fine and not doing anything.
I'm wondering how do I debug this and figure out whether it's Code itself or an Extension causing the issue? If so how do I find out which extension it is?
Process Explorer is builtin in vscode.
It can be opened using menu by going Help => Open Process Explorer

What code should I use? sys.exit() or some other thing I haven't found?

I'm a high school student in a class that is using Python 2 on Enthought Canopy Windows Edition. I often get stuck in coding loops, but the only way I can get out is by closing out all forms of open Enthought. Is there any more reliable way to do it? I've been using sys.exit(0), but it doesn't work correctly, and is leaving my coding in a jam. I can't even test it without it getting me stuck. Anyone know how to fix this issue?
If your code is already running, then you can't reliably type a command to stop it, because the prompt won't necessarily be live then.
Often you can use the Run menu's "Interrupt kernel" command, and you should usually be able to use "Restart kernel", though this doesn't work all the time.

working with workspaces and Pydev in Eclipse

im not sure what i did.. but i am working through some tutorials to get up to speed on python, and i started getting this error message... any ideas on how to fix this? from the error, i looked up the message, and it looks like wham i press the run button it is looking for a file that is no longer there.... but I'm not even working on that file anymore... I'm trying to run something different that does not refer to the previous file.
what does work is if i do run as.. but id rather not do that every time. I'm sure there is a setting I'm just not aware of that i messed up.
Well, not sure how exactly you're getting to that point from your explanation, but please take a look at: http://pydev.org/manual_101_run.html to see how to properly run a module inside PyDev.