Program stops execution if window loses focus. Why? - gnome-terminal

I am running a big python script on a bash terminal. The problem is that everytime I use Alt+Tab or click outside the terminal into another windows (Say, google-chrome), the program stops execution. Then I need to put the terminal back in focus by clicking inside it to resume execution. This keeps happening all the time.
What could be wrong?

Related

Why my python script sometimes stopping and waiting for keypress?

I noticed something on my script. Sometimes it stops and when I press any keys on my keyboard it resumes. I didnt put any keypress command on my script. It's running on a windows vps.
Any idea why is this happening?
I found the issue. When i clicked on the terminal the script pauses. To fix this go to terminal properties then uncheck the quick edit.

How do I make my compiled program not immediately close when it finishes running the code?

I'm trying to test out if the compiled rust program is portable but the window immediately closes. Opening the program in a terminal in vs code doesn't immediately close the program but waits for you to enter any key before closing. Is there a function or any code that would make it act like that?
Opening the program in a terminal in vs code doesn't immediately close the program but waits for you to enter any key before closing.
I'd guess that's just the vscode behaviour. Immediately closing the window is the normal behaviour for a program terminating.
Is there a function or any code that would make it act like that?
Reading from stdin usually does the trick.

Python closes immediately before executing

when I execute my code, it causes the execution window to open up and close instantly. Note that this is prior to execution of my programme, as the several inputk=input("blablabla") I have in my code don't show up before the window closes.
I ask for advice on what is happening.

running x11 on cygwin, all terminals stuck at one corner

I am trying to run x11 on cygwin, mainly to run xfig utility, and I am facing a problem.
When I run xinit to start x11, I get a big popup window with one terminal open. But I am unable to open any other terminals in it. To be more specific, when I run "xterm &" in it, a new terminal opens up but it sits on top of the old terminal, and there is no way I can move this window, so the old terminal is as good as useless to me, till I kill the new terminal.
I also tried running "xwin". There a big window popped up, but it does not contain any terminal, and I cant open any terminal, whether by left or right clicking.
I also tried running "startx". A big window opens up but gets killed automatically after a few seconds.
How can I use x11 effectively on cygwin? As of now, I can use with "xinit", but with only one terminal.
The proper mode to start the Xserver on cygwin is to use starxwin.
From its manual:
The startxwin script is a front end to xinit(1) that provides a
some what nicer user interface for running a single session of the X Window
System in multiwindow mode. It is often run with no arguments.
To move windows around, you need to have a window manager running. You can start this either from the xterm, by passing the name of the window manager as an argument to startx, or by starting it from your X11 startup configuration (memory says that would be ".xinitrc" in your home directory on most unix boxes, but I am not sure if that's true on Windows using Cygwin). The .xinitrc file is "just" a shell-script, with the end of the script indicating "X should shut the server down now" (see example at the end).
There are many possible window managers, including fvwm2 (which according to your comment, you managed to find on your own). A full list of X11 window managers is probably too long to fit in this answer (there are many, there are new ones popping up, and old ones going out of maintenance on an ongoing basis). Some of the not entirely uncommon ones are fvwm2 (already mentioned), cinnamon, twm, ctwm, ratpoison, ... For a more up-to-date list, ask your favourite search engine for "list of X11 window managers".
Example .xinitrc file:
# This is an example .xinitrc file, starting first an xterm,
# then a window manager. As the X server terminates when this script
# does, we start the X terminal in the background, but the window
# manager in the foreground, so that "WM exists" signals "X server shuts down"
xterm &
fvwm2

Ocaml Graphics.open_graph won't work in script mode

I'm trying to use the ocaml graphics module.
The line:
#Graphics.open_graph "";;
works fine in the interactive module, i.e. a small window pop up in X11 with white background.
However, when I try to use the script mode -- put this line in a file then compile it:
ocamlc -o a.out graphics.cma code.ml
only X11 starts but with no window popup.
Am using a mac. Anyone knows why? Thanks.
Followup:
It seems under script mode the popup window will closeup immediately after code execution. Because if I compile using XTerminal, I can see a small window popup but then closes.
I managed to keep the window open by adding an infinit loop at the bottom:
while true do () done;;
But still don't understand how things really work. Please help. Thanks.
All ressources are freed when the script terminates: memory, file descriptors, including the X window.
If you add an infinite loop, the script does not terminates, and the windows stays open.
Likewise, under the toplevel, the window stays open as long as you don't close the toplevel.
I would suggest to add two lines add the end of your script:
print "press enter to exit"
read one line from keyboard input
This way the script will not terminate until the user presses enter.
Indeed, as jrouquie explains you need to delay the termination of your program. The way I personally do that is by waiting on user input. At the end of the interactive program (or function being studied that opens the graphic mode), I put:
ignore (Graphics.read_key ())
This will wait until a key has been hit on the keyboard, and ignore the key value before returning.

Resources