fxn
I have a script executed with mix run that has an infinite loop that collects some data in an agent. I’d like to print that data when I interrupt the script.
Tried System.at_exit/1 without success, maybe because the only way I know to interrupt the execution is C-c C-c.
Is there a way to accomplish that?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
New article: Elixir Public vs Private Functions
I’ve published the next article in my Elixir learning series on dev.to, exploring private...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
Ctrl+C, Ctrl+C kills the Virtual Machine. Ctrl+G, Q should exit in a way that the exit handler gets called, alternatively you can try
kill $BEAM_PIDfrom another terminal.fxn
I am trying
C-g+qdoes not seem to interrupt the script here, andkilldoes, but does not triggerSystem.at_exit/1.rvirding
That is weird. What output do you get when you do Ctrl-G? It should be something like
Try doing ?
Btw you did press Enter after the q? It is not stated anywhere but otherwise nothing happens.
fxn
When I type Ctrl-G nothing happens apparently, I have recorded a GIF.
Is that strange? This is macOS and
elixir -vreturnsThey two are installed with
asdf.axelson
Just throwing out a random idea, but is it different if you execute the script with
mix run?fxn
With
mix runhappens the same, indeed I was tryingelixirto remove Mix from the equation.I have revised shortcuts in iTerm2 in case
C-gis intercepted, but don’t find anything. Terminal.app makes no difference either.C-g qshows “User switch command” in IEx and erl, which to me suggests the character is actually not intercepted by my terminals or my OS. However,System.at_exit/1does not seem to be invoked:Also, I have replaced the sleep call with a dummy
receiveblock, just in case sleeping meant whatever code needs to be triggered byC-gis just within the slept process. No luck either.Does
print “Bye!” in your machines using
C-g q?fxn
Ah, I also tried in a Docker container that runs Linux, same.
ChrisYammine
This may be of interest to you: https://stackoverflow.com/questions/42324276/catching-exit-signals-in-elixir-escript
AFAIK erts will trap the TERM signal and call init:stop, but when you’re C-c ing that’s an INT signal. You should be able to achieve your desired behavior with a bash wrapper like in the linked stack overflow question.
fxn
However, several people in this thread say
C-g qshould work. Note thatC-gdoes not send a signal, you get the control character 7. If that is possible, a shell script wrapper would be overkill.I just need to interrupt a script in an ordered way. I have an
at_exitcallback, but could be taking down a supervision tree orderly or whatever.rvirding
A thing to realise here is that the handling of Ctrl-G and its commands only work when you are running a shell. Without a shell this interface is not generally not started. You can see this if you look in the
elixirshell script and see that when an iex shell is not start then there is a-noshellargument to the resultanterlcommand. Doingelixir foo.exsdoes not start a shell and, hence, no handling of Ctrl-G and q.