SBCL Ctrl-C on Windows - common-lisp

In SBCL on Windows, if a bug in my code causes an infinite loop, by default, control-C does nothing. I have to kill the entire console (by clicking X at the top right of the command prompt window).
Is there a way to get control-C to break out of the loop?

Related

Jupyter notebook seems to remember previous path (!pwd) after being moved to a different directory?

I initially had a notebook in one directory in AWS SageMaker JupyterLab, say /A, but then moved it into /A/B. However, when I run !pwd in a jupyter notebook cell, I still get /A. This happens even when I press 'restart kernel'. How does the notebook remember this, and is there a way to prevent or reset this?
Thanks
I was actually using AWS SageMaker, and restarting the kernel from the toolbar was not enough. I needed to restart the kernel session, by pressing 'shut down' in the "Running terminals and kernels" section on the left navigation.
They are currently discussing warning users about the need to restart the kernel when a notebook is moved.

Octave: How to prevent plot window from closing itself?

From the octave CLI or octave GUI, if I run
plot([1,2,3],[1,4,9])
it will display a plot window that I can look at and interact with. If however I create file myPlot.m with the same command as content
plot([1,2,3],[1,4,9])
and that I run it with
octave myPlot.m
then I can briefly see the plot window appear for a fraction of a second and immediatly close itself. How can I prevent this window from closing itself?
Octave 4.2.2
Ubuntu 18.04
Here is a full example, given the confusion in the comments.
Suppose you create a script called plotWithoutExiting.m, meant to be invoked directly from the linux shell, rather than from within the octave interpreter:
#!/opt/octave-4.4.1/bin/octave
h = plot(1:10, 1:10);
waitfor(h)
disp('Now that Figure Object has been destroyed I can exit')
The first line in linux corresponds to the 'shebang' syntax; this special comment tells the bash shell which interpreter to run to execute the script below. I have used the location of my octave executable here, yours may be located elsewhere; adapt accordingly.
I then change the permissions in the bash shell to make this file executable
chmod +x ./plotWithoutExiting.m
Then I can run the file by running it:
./plotWithoutExiting.m
Alternatively, you could skip the 'shebang' and executable permissions, and try to run this file by calling the octave interpreter explicitly, e.g.:
octave ./plotWithoutExiting.m
or even
octave --eval "plotWithoutExiting"
You can also add the --no-gui option to prevent the octave GUI momentarily popping up if it does.
The above script should then run, capturing the plot into a figure object handle h.
waitfor(h) then pauses program flow, until the figure object is destroyed (e.g. by closing the window manually).
In theory, if you did not care to collect figure handles, you can just use waitfor(gcf) to pause execution until the last active figure object is destroyed.
Once this has happened, the program continues normally until it exits. If you're not running the octave interpreter in interactive mode, this typically also exits the octave environment (you can prevent this by using the --persist option if this is not what you want).
Hope this helps.
Run #terminal as (need to exit octave later)
octave --persist myscript.m
or append
waitfor(gcf)
at the end of script to prevent plot from closing

Julia Jupyter Notebook persists despite logout from browser

Running Julia in a terminal (macOS) and then launching a Jupyter notebook
julia> using IJulia
julia> notebook(detached=true)
This works fine. However when I log out of the notebook and closing the browser, there is still a jupyter-notebook running and I have to kill -2 pid to make it go away.
Is this expected behaviour? Is there a parameter I need to set somewhere?
Yes, this is the expected behaviour for the way you've called notebook. The server doesn't stop when your browser page is closed (you might open another, for example!). Using the detached keyword argument means the server process is started in the background, so doesn't block the Julia session you started it from, so you'd have to do extra work if you wanted to stop it from there. From the IJulia readme:
You can use notebook(detached=true) to launch a notebook server in the background that will persist even when you quit Julia

Suppress messages from the IPython Notebook engine

I usually start the IPython Notebook engine and put it in the background. But whenever users open/close notebooks or timeouts happen, I see the background spitting out messages on the terminal from where I started it - which is kind of annoying.
Is there a way to suppress those and make the engine stay silently in the background? I suspect this might be a simple switch at startup.
I forgot the simple piping of the output to /dev/null, which does the trick:
alias start_ipy='cd /path_notebook_folder; ipython notebook --profile=nbserver --no-browser --pylab inline --port=443 2>/dev/null >/dev/null &'

Ruby Command Line: How can I send the CTRL-C command via text in the command line?

I am trying to create a simple Automator droplet that will take the style.less file dropped into it and run the following LESS command on it:
$ LESSC {DROPPED_FILE} --watch
which will monitor the file I have dropped in for any changes and will then automatically update the outputted style.css
FYI: I am using LESS to have dynamically written CSS files. More info is here.
The basic droplet works great.
The dropped file is passed into a variable; For this purpose: {MY_VAR}.
I run a shell script in the /usr/bin/ruby shell as follows system("lessc {MY_VAR} --watch &")
this works great however I want the --watch to be stopped upon quitting the automator app.
The LESS documentation says to press the CTRL-C shortcut while in the command line shell to abort the script.
But since I am not inside the terminal window (command is being passed in the background) I don't know how to abort the script.
Even after the automator.app has been closed the style.less file is still being watched for changes and the correspondingly generated style.css is still being rewritten.
So basically I need to pass the abort command on exit of the .app.
I have generated a simple pop up that on click will close the app after passing another command to the terminal shell.
This is the part where all my tries have been unsuccessful to stop the script.
Is there a command line function that acts the same as pressing the CTRL-C command?
How would I pass this the best to the shell?
If you press CTRL-C in your console, this is not send via STDIN to your programm. Bash(or whatever you use) treats CTRL-C special. The bash sends a signal to the process. In case of CTRL-C this is SIGINT. To send a signal to a program you need to no it's pid. Then you can send the signal to the pid. To be able to get the pid you can start the process with ruby.
p= IO.popen("lessc #{file} --watch")
pid= p.pid
Process.kill("INT", pid)
In ruby there are at least 3 different ways, of executing something.
`lessc #{file} --watch` # returns stdout after exit
system("lessc #{file} --watch") # returns the integer return value after exit
Io.popen("lessc #{file} --watch") # returns imidietly an io object, where STDIN and STDOUT can be written and read
You used system("lessc #{file} --watch&") which also returns imidietly but always returns 0.
Hint: What does ^C Control-C really do in a shell?
(It doesn't send a character).
Clarification on hint:
This PDF talks about signals. Note where it also talks about ^C. Your can manually send a signal as required.
When you press ^C in a terminal it normally sends the SIGINT signal to the program that is running. You can send these signals in Ruby as well. More information about working with processes (and sending signals) in Ruby: http://whynotwiki.com/Ruby_/_Process_management.
Happy coding.
less also terminates when it receives the "q" character, I think.

Resources