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

How to prevent awesome from quiting from inside async callback attached to exit signal of awesome? #3429

Open
actionless opened this issue Sep 8, 2021 · 11 comments

Comments

@actionless
Copy link
Member

No description provided.

@sclu1034
Copy link
Contributor

sclu1034 commented Sep 8, 2021

As far as I can tell, awesome_atexit doesn't care about anything that happens in the exit signal handlers. So I don't see a way to prevent awesome from exiting, even in a synchronous signal hander.

And if it really has to be a truly asynchronous callback, then awesome_atexit would have to keep the event loop running until something determines that all callbacks that might want to prevent this have had the chance to do so.

@actionless
Copy link
Member Author

actionless commented Sep 8, 2021

i was thinking mb about exit_async signal, which would be passing callback as a first argument - and waiting until that callback will be called

@Elv13
Copy link
Member

Elv13 commented Sep 8, 2021

i was thinking mb about exit_async signal, which would be passing callback as a first argument - and waiting until that callback will be called

Can you clarify, you want to run this callback later in something like gears.timer? Or do you just want a gears.timer.delayed_call? Can you clarify the use case (I guess an exit popup like macOS with a 30 second timeout)?

@actionless
Copy link
Member Author

the usecase:

  1. i have function which writes state of some things into a file

  2. on exit signal i want to save the state

  3. i recently refactored save function to be asynchronous, to make it smoother when saving state not only on exit

  4. so now basically exit signal only triggers the start of saving, but awesome restarts before async function finished saving state

@actionless
Copy link
Member Author

so ideally i would like it look like this:

awesome.connect_signal('exit_async', function(callback)
    my_lib.save_state(function()
        callback()
    end)
end)

@Elv13
Copy link
Member

Elv13 commented Sep 8, 2021

That might be a shitty question, but: can't you just make it optionally synchronous? This seems like a lot of complexity just to turn an async call into a sync one. Or if you can get your hand on the glib main loop object, you can just block on it?

@actionless
Copy link
Member Author

actionless commented Sep 8, 2021

i wonder is there any relatively painless way to do?

awesome.connect_signal('exit', function()
    some_lib.wait(function(callback)
        my_lib.save_state(function()
            callback()
        end)
    end)
end)

@Elv13
Copy link
Member

Elv13 commented Sep 8, 2021

(this is a copy/paste from the other issue, because I failed at paying attention)

I don't think "just" running something in gio.Async.start makes it async. Do you use the "real" async version of the Gio functions? But beside, I was referring to 2 things:

  1. Keeping a blocking version of that function.
  2. With the glib mainloop object, you can block and wait for events directly, so you can turn any async coroutine into a synchronous function. It's a hack, but it should work.

Reading https://www.freedesktop.org/software/gstreamer-sdk/data/docs/2012.5/glib/glib-The-Main-Event-Loop.html , I think you need to get the look context and acquire it, then g_main_context_iteration it a few time, but the doc is pretty confusing, so it might do something completely different.

i meant to wrap async functions inside that thing to avoid side-effects which you mentioned before, or did i got it wrong?

Doing the thing above can work. But that's still more work and hacky-er than just having a synchronous version of your state saving function.

@actionless
Copy link
Member Author

actionless commented Sep 9, 2021

in my particular case restoring sync version of save function was only 4 lines of code, but in general i think that's still quite a problem, especially for checking unsaved apps, as you mentioned before

offtopic:
for checking unsaved apps for now i have 2 workarounds

  1. awesome started not directly from x session, so if awesome quit/crashes, X server continue to run with the rest of the apps

  2. i simply overriden menu item for shutdown to first check the apps before shutting down)

(i know what both should be handled by apps called Session Managers, and i even tried using 3 of them, from GNOME, XFCE and MATE for quite a while, but rewriting it in couple of lines of lua at the end was working less buggy)

@actionless
Copy link
Member Author

what do you think about having smth like this?

awesome.connect_signal('exit', function()
    awesome.cancel_exit()
    my_lib.so_smth(function()
        awesome.exit()
    end)
end)

@Elv13
Copy link
Member

Elv13 commented Sep 9, 2021

Yeah, that would work

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

No branches or pull requests

3 participants