Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terminal persistence after crash #2703

Closed
ruminations opened this issue Dec 23, 2020 · 8 comments
Closed

terminal persistence after crash #2703

ruminations opened this issue Dec 23, 2020 · 8 comments
Labels

Comments

@ruminations
Copy link

ruminations commented Dec 23, 2020

23 December 2020 Noon

geany version: 1.32
ubuntu version: 18.04

Lately I've been running my machine until it shuts off from a drained battery.

Today I noticed that when I run python programs using the toolbar execute button, the icon
does not change back to a gear from the circle-slash when the program finishes.

The practical effect of this is you have to click the button again to get the gear icon, but the
terminal closes instead of remaining open. This is very inconvenient since it makes it impossible to compare outputs from two different versions side by side.

27 December 2020: this workaround is incorrect:
see: #2708
for a complete explanation and resolution for this bug.

Workaround

I solved the problem by opening the "set build commands" dialog and changing the execute command to something that throws an error, e.g. python "%p%f" (no '/' between), running something, and then changing the execute command back to its original value. (python "%f")

Evidently, geany stores some state that is not reset owing to the crash, and in some cases is not sanitized on startup.

@elextr
Copy link
Member

elextr commented Dec 23, 2020

When you say the laptop "shuts down" do you actually mean shutdown, or hibernate or suspend?

@elextr
Copy link
Member

elextr commented Dec 24, 2020

If the Geany execute command item is activated while a command is running it terminates the command, this allows programs that get into an infinite loop to be terminated. When running in a terminal Geany does not know the process ID of the program, only of the terminal, so that is what is terminated, and hopefully it will terminate the program. Similarly as it does not know the program process id there is no way Geany can find out if the program has finished, only if the terminal has finished, so the execute action remains as "stop" until the terminal closes. So this part is working as intended.

Geany does not store any execute state when it closes because it no longer owns the terminal process when its restarted (if that process still existed) so there is no point in it doing so. I suspect that if the execute icon stays at stop then your laptop is not shutting down, it is hibernating or suspending, so Geany is restored in its previous state, but I have no idea if the terminal process termination is correctly delivered in that case, possibly not, but its not a scenario Geany has been designed to cope with, YMMV.

If you want to have multiple terminals open the command Geany runs (from Preferences->Tools->Terminal) must complete. I havn't tried it, but you could try modifying that preference to run the terminal in a shell and detaching it.

@elextr elextr added the invalid label Dec 24, 2020
@ruminations
Copy link
Author

ruminations commented Dec 24, 2020 via email

@ruminations
Copy link
Author

ruminations commented Dec 24, 2020 via email

@elextr
Copy link
Member

elextr commented Dec 25, 2020

Well as I said, Geany does NOT store anything about running subprocess state, and even if it did nothing gets stored if its crashed. Thats why I am suspecting that your laptop is suspending or hibernating when its battery goes flat, which may store Geany's in memory process state and restore it hence getting the same menu state. I note that suspending works as advertised in your experiment, if you still have battery, but maybe its not so reliable if the battery dies. But Geany has no knowledge of suspension and resumption, so its nothing it caters for, its entirely up to your OS and desktop if it works and Hiesenbugs are common in Linux suspend/hibernate/resume IIUC.

The menu behaviour is as it was intended since 0.19 (IIRC) but its possible that in the past there was a bug in the process spawning code that returned the menu immediately, but the spawning code was mostly re-written at some point since then, possibly removing the "unintended feature". This change in behaviour has been pointed out before, but AFAIK no conclusion was reached as to why it happened, but as I said its now working as intended. Did you try running the terminal from a shell and detaching it to allow multiple terminals?

Your environment problem is most likely because you do not start Geany from a shell (maybe a menu or shortcut). In that case nothing reads your shell startup files to set PYTHONPATH so Geany does not inherit it. Changing the menu/shortcut command to run Geany from a shell should fix that. Tell your distro packagers to fix the menu/shortcut, Geany does not make that. Alternatively your distro may have aliased sh to dash not bash so again the startup file is not read.

@ruminations
Copy link
Author

25 December 2020 Noon

First of all, the sub-process state is irrelevant as is suspension and hibernation. What is relevant is the state of the geany user interface, and surely there is state storage of that if only in RAM.

Second of all, I am talking about a complete power failure, intentionally induced. This is not suspension or hibernation. It is the same thing that would happen if you pulled out the battery while your machine is running only on the battery. The only remedy is a cold reboot with wall power, and that is my underlying intention. In fact, when I do reboot, it is very clear it is a cold reboot. I am not naive or a noob. I understand these systems down to the device level, and have programmed them at the device level. I know the difference between these various power states very well.

Thirdly, I do not understand the meaning of your second paragraph, but if I infer correctly, you are reasserting the incorrect idea that the circle slash persists during execution during normal behavior and the x-terminal can be killed by clicking. Manifestly, empirically, this is not the case, and never has been in my experience, at least with python code which is all I use geany for. The only way to kill an execution is with ^C, closing the window, or any key entry after the sub-sub-process has finished, which closes the window. If it is the developer's intention that the gear icon not be restored immediately (after the x-terminal spawn), that in my view is a bad design choice and is actually a deal breaker for me using your software, should your software actually change to behave that way. Once again, it currently does not. It would be an utterly useless feature to kill a sub-process with an icon click. The existing mechanisms are perfectly fine.

To be clear, the circle slash appears to be only briefly visible during x-terminal spawning (an X-window application not a shell), which itself spawns a shell which spawns the actual program being executed. There are three processes spawned. These three processes are clearly visible in the task manager. If there is already an x-terminal instance running somewhere else, only the shell and the actual program processes are spawned. This is empirical observation and is indisputable.

FourthIy, running multiple x-terminals is not a problem. That is normal behavior and it is still normal behavior after I fixed the issue with my workaround. I'm not going to waste time detaching shells when I have the behavior I want already, which is the behavior geany has always exhibited, and the fix persists across geany restarts.

Finally, my "environment problem" is not a problem. I merely explained why my geany.conf is slightly different from the default. To be complete, I ran 'which sh' and get /bin/sh, which is perfectly fine with me (not a problem), and perfectly explains why I needed to alter geany.conf, which again, is not a problem. In fact, it is preferable to be using a lightweight shell in this context, so the distro packagers made a good design choice.

The geany failure I discovered was accidentally discovered and is very real.

Now with that out of the way, let us proceed rationally.

I am now making sure every night, when I force a power failure, that I am using geany and nothing else.

I can tell you this:

  1. The problem occurs when I run a program and the power surge from that action forces the battery burn down over the edge. The machine shuts off immediately.

  2. Since I ran a program, the geany user interface has momentarily changed the icon to the circle slash at the moment of power failure.

  3. Since the circle slash is momentarily visible in any normal case, at least one of three things must be happening:

a) there is a programmed delay of perhaps half a second before returning to the event loop
b) geany is noting the user interface state change to a disk file, which takes a little time
c) the process spawning is not as fast as it might be for some reason

I do not know which is true, but at least one must be true, for otherwise the circle slash would never be visible in the user interface, because even the slowest decade old machine is truly very fast.

  1. Any of those three possibilities is interrupted by the power fail, possibly signaled to geany by a kernel signal, but with little or no time to do anything about it.

  2. After coming up cold, geany clearly loads state information from geany.conf, and doubtless sets various internal defaults. All complex programs do that. It is common enough that the complexity obscures some of this and some state settings are overlooked, either because they are not in the .conf file or because they are overlooked due to the myriad other concerns that a programmer has to deal with. Mistakes happen. That is reality.

  3. The bad behavior is not remedied by closing geany and restarting it. That is the first thing I tried. There is therefore some user interface state setting somewhere that is reloaded.

  4. The bad behavior is remedied by twiddling with the execute command in the Set Build Commands dialog.

  5. My memory of the sequence of events leading to realization that I had a remedy is muddied, but it is clear that it results from the sequence of programmed actions executed either by clicking 'OK' in the build settings dialog, or by the error processing events that occur when when the gear icon is clicked and the build settings execute command is faulty. This greatly limits the code blocks that need to be examined to determine what user interface state setting is being missed during startup. Those two code blocks are changing settings, one because of a user request. The error processing is not necessarily altering settings, but it certainly might be, and that would seem logical - when you encounter a fault, you usually want to flag it. If so, it may not be the flagging that remedies, but the existence of the flag when the build settings are next saved with 'OK'.

  6. By examining those code blocks you can quickly determine what to look for in the startup code and remedy the problem.

All of this is assuming geany is well designed, and I think it is.

In the meantime, I will continue to burn my battery down every night, and at some point, I will reproduce the error, pay closer attention to the remedy sequence, and report it here.

@elextr
Copy link
Member

elextr commented Dec 26, 2020

First of all, Geany is a totally volunteer project, people work on it in their own time, and cover a wide spectrum of knowledge and experience. I am likely older and have more coding experience than you (and I like to think capable of being grumpier than most 😁) so there is no need for reports that appear to be rants with bolded text demanding people do things. Volunteer projects don't work that way, it just turns people off helping you.

First of all, the sub-process state is irrelevant as is suspension and hibernation. What is relevant is the state of the geany user interface, and surely there is state storage of that if only in RAM.

Of course, but this is irrelevant if Geany is closed and restarted, the value is reset, it is not stored and restored. Since you "know these systems very well" you will therefore know that any state in memory is not restored when a process is closed and started again unless the program stores it and reloads it. Since Geany does not store and reload it the only reasonable solution I can think of at the moment is that it was being restored from hibernation.

Thirdly, I do not understand the meaning of your second paragraph, but if I infer correctly, you are reasserting the incorrect idea that the circle slash persists during execution during normal behavior and the x-terminal can be killed by clicking. Manifestly, empirically, this is not the case, and never has been in my experience, at least with python code which is all I use geany for.

WFM, in Geany 1.36 to 1.38 that I have available, if it doesn't work perhaps it was a bug back in 1.32 although I don't remember such a fix. Or whatever terminal you are using has unusual behaviour (see below).

that in my view is a bad design choice and is actually a deal breaker for me using your software

That is of course your personal view and choice, but before you throw your toys out the cot, did you try my suggested workaround, although from your description below it seems the misbehaving terminal application is doing what you want already.

To be clear, the circle slash appears to be only briefly visible during x-terminal spawning (an X-window application not a shell), which itself spawns a shell which spawns the actual program being executed. There are three processes spawned. These three processes are clearly visible in the task manager. If there is already an x-terminal instance running somewhere else, only the shell and the actual program processes are spawned. This is empirical observation and is indisputable.

Then you are not spawning xterm, which is the default Geany setting, but some other terminal window application, which is combining multiple invocations into one detached process instead of running separate processes. So this is why it returns immediately to Geany and the icon changes back.

This is information that has been missing from your previous descriptions, although you still havn't actually named which terminal application it is running. Remember I can't see your machine, I don't know anything about it except what you tell me.

FourthIy, running multiple x-terminals is not a problem. That is normal behavior and it is still normal behavior after I fixed the issue with my workaround.

This contradicts your statement above, does the terminal application run multiple processes or one process with multiple windows?

I'm not going to waste time detaching shells when I have the behavior I want already, which is the behavior geany has always exhibited, and the fix persists across geany restarts.

So clearly didn't try the workaround, nor (from your description of "waste time detaching shells") even understood it, but clearly the errant behaviour of your terminal application is suitable for you, so that means Geany can keep the behaviour it has always had, and you are also "happy". But it does mean you have a non-standard setup and need to provide additional information when reporting problems.

So having dealt with several rabbit holes, back to the original problem.

Second of all, I am talking about a complete power failure, intentionally induced. This is not suspension or hibernation.

My Linux laptop automatically hibernates if the battery gets low before it shuts down, and since Geany does not store and restore execute icon state, I therefore look for alternatives that can restore state, such as a hibernate.

Since the circle slash is momentarily visible in any normal case, at least one of three things must be happening:

a) there is a programmed delay of perhaps half a second before returning to the event loop
b) geany is noting the user interface state change to a disk file, which takes a little time
c) the process spawning is not as fast as it might be for some reason

and the likely answer is:

d) the icon is changed at the initial activation and cleared after the terminal application has spawned and created its window and started a shell and started Python, and reported its terminated even if it isn't, all of which will cause a delay and steal cpu cycles from Geany and the X server that does the displaying of the icon and add to the poll loops that exist (IIUC) in the GTK/Glib toolkit communication with the X server and the signal handlers. So the icon being visible for a short time is pretty likely without any explicit coding.

After coming up cold, geany clearly loads state information from geany.conf ... Mistakes happen. That is reality.

Yes, which does not include the state of the execute icon, that is initialized with g_new0() which returns cleared memory. Sure everybody makes mistakes, but unless someone manages to point out where the code can avoid starting with the state value 0 then something else is going on (like weird terminal apps above), see build.c.

is not remedied by closing geany and restarting it. That is the first thing I tried. There is therefore some user interface state setting somewhere that is reloaded.

I hear you but until either somebody replicates it, or points to the code path (see above) its impossible to know whats happening.

So pending that I am working on the basis that "something else" is happening, however from the information provided its not possible to say what.

remedied by twiddling with the execute command in the Set Build Commands dialog.

Yes if "something" causes the execute state to be out of sync it needs to be "tricked" into changing state since the process its monitoring no longer exists and so its state will never change. Just lucky the code clears the state on an error, even though theoretically its doesn't need to. That does not help finding the cause though.

By examining those code blocks you can quickly determine what to look for in the startup code and remedy the problem.

Thank you for volunteering.

In the meantime, I will continue to burn my battery down every night, and at some point, I will reproduce the error, pay closer attention to the remedy sequence, and report it here.

As noted above, the remedy is understood, its how it gets it out of sync that is interesting and useful. I doubt anyone else is going to flatten their laptop batteries to try to replicate the exact conditions, so yes its only you who will reproduce it. Try to provide as much information as possible when it happens.

@ruminations
Copy link
Author

27 December 2020
8 PM

The good news:

I've figured this out. See: #2708

The bad news:

The bug is completely deterministic and much worse than I thought.

I won't trouble you with the details of false correlations, mis-directions, confusion and frustration that has beset me the past few days.

Suffice it to say that if we hadn't butted heads over our very different experiences with geany, I never would have looked at the things that I needed to look at to resolve the ambiguities.

Long story short: we are both right.

You are correct that geany is designed for single execution.

I am correct that all I have ever experienced is a wonderful development environment for multiple simultaneous processes.

I am now closing this issue, which is only useful in the sense that it led to clear understanding as expressed in: #2708

Resolving #2708 is up to you and the geany developers. I can only hope you take heed of my concluding remarks. As of now, I wash my hands of this and return to my other tasks, since I now have a deterministic understanding of how to control the anomalous behavior of geany that actually is not anomalous, but only very complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants