Discussion:
[Deluge] #3011: Listen to WM_ENDSESSION on Windows
Deluge
2017-03-27 09:30:52 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
-----------------------------+------------------------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: needs verified
Component: Unknown | Version: other (please specify)
Keywords: |
-----------------------------+------------------------------------
Right now, on Windows, when a torrent is downloading and Windows' session
ends (Either via shutdown or log off) Deluge is forcedly shutdown and the
torrent goes into error state. It needs to force recheck the next time
Deluge is started.

Suggest listening to the WM_ENDSESSION message so that Deluge can
gracefully exit and not push incomplete torrents into error state.

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-03-27 09:53:10 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+------------------------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: needs verified
Component: Unknown | Version: other (please specify)
Resolution: | Keywords:
------------------------------+------------------------------------

Comment (by Cas):

Could you enable debug logging and look for `ctrl_type:` entry as it might
be missing an event.

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:1>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-03-27 11:11:59 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+------------------------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: needs verified
Component: Unknown | Version: other (please specify)
Resolution: | Keywords:
------------------------------+------------------------------------
Changes (by joeyvh):

* Attachment "deluge.log" added.


--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-03-27 11:15:01 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+------------------------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: needs verified
Component: Unknown | Version: other (please specify)
Resolution: | Keywords:
------------------------------+------------------------------------

Comment (by joeyvh):

Attached deluge.log

Test case: Set log level to "Debug". I had already added a torrent to
test. After opening and leaving open for a while, I shut down the PC with
deluge still running.

There seems to be no mention of "ctrl_type" at all anywhere in the log
file.

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:2>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-03-27 11:36:36 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+------------------------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: needs verified
Component: Unknown | Version: other (please specify)
Resolution: | Keywords:
------------------------------+------------------------------------

Comment (by Cas):

Hmm ok, thanks. I shall have to look into how to implement `WM_ENDSESSION`
in Python.

You could see if using `deluge-debug.exe` or switching to Thinclient mode
works in the meantime.

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:3>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-03-27 13:22:51 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+------------------------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: needs verified
Component: Unknown | Version: other (please specify)
Resolution: | Keywords:
------------------------------+------------------------------------

Comment (by joeyvh):

Alright, thank you. For now I'll simply be extra careful to quit deluge
before shutting down the PC when a download is running.

If I can do anything to help test / debug, please let me know.

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:4>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-03-30 21:59:12 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+------------------------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: 1.3.15
Component: Unknown | Version: other (please specify)
Resolution: | Keywords:
------------------------------+------------------------------------
Changes (by Cas):

* milestone: needs verified => 1.3.15


--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:5>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-05-11 11:17:49 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+--------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: 1.3.15
Component: GTK UI | Version: 1.3.14
Resolution: | Keywords:
------------------------------+--------------------
Changes (by Cas):

* version: other (please specify) => 1.3.14
* component: Unknown => GTK UI


Comment:

Collated information for ongoing dev...

* [https://msdn.microsoft.com/en-us/library/ms700677(v=vs.85).aspx
Application shutdown documentation]
* [https://msdn.microsoft.com/en-
us/library/windows/desktop/aa376890(v=vs.85).aspx WM_QUERYENDSESSION]
* [https://msdn.microsoft.com/en-
us/library/windows/desktop/aa376889(v=vs.85).aspx WM_ENDSESSION]
* [https://msdn.microsoft.com/en-
us/library/windows/desktop/aa376877(v=vs.85).aspx
ShutdownBlockReasonCreate]
* [http://stackoverflow.com/q/31374339/175584 SO - Process WM_ENDSESSION,
WM_QUERYENDSESSION]
* [http://stackoverflow.com/q/520910/175584 SO - simulate Windows shutdown
for debugging]


Code to test pid handling messages:

{{{#!python
from win32con import WM_QUERYENDSESSION
from win32gui import EnumWindows, GetClassName, IsWindowEnabled,
IsWindowVisible
from win32process import GetWindowThreadProcessId

def get_hwnds_for_pid(pid):
def enumwins_cb(hwnd, hwnds):
if IsWindowVisible(hwnd) and IsWindowEnabled(hwnd):
# print(GetClassName(hwnd), GetWindowThreadProcessId(hwnd)[1])
if pid == GetWindowThreadProcessId(hwnd)[1]:
hwnds.append(hwnd)
return True

hwnds = []
EnumWindows(enumwins_cb, hwnds)
return hwnds

def shutdown_pid(pid):
win32api.PostMessage(get_hwnds_for_pid(pid)[0], WM_QUERYENDSESSION)

}}}

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:6>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-12-22 08:28:23 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+--------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: 1.3.16
Component: GTK UI | Version: 1.3.14
Resolution: | Keywords:
------------------------------+--------------------

Comment (by DjLegolas):

As I wrote in the [https://github.com/deluge-torrent/deluge/pull/155 pull
request], I wrote a handler for this in [https://github.com/deluge-
torrent/deluge/commit/ef6ca969413a0e7c30edc278638384be1e312429 my fork].

On `WM_QUERYENDSESSION` message, Deluge will register itself as a
Shutdown-Blocker.
Next, when receiving `WM_ENDSESSION` message, Deluge should have 30
seconds to save all the data - depending on whether critical shutdown or
not.

But the lack of a proper tool for testing this makes me feel like the is
something wrong with my work.

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:8>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2017-12-24 17:52:15 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+--------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: 1.3.16
Component: GTK UI | Version: 1.3.14
Resolution: | Keywords:
------------------------------+--------------------

Comment (by Cas):

Have you done any testing of your proposed changes? It's been a while
since I touched this code so can't remember exactly where I was but
testing was a challenge. I only use Windows on virtualbox VMs which makes
it a bit easier for actual OS restarts.

I think it is possible to block shutdown entirely if Deluge doesn't return
True at some point.

Also you only really need to do this shutdown blocking in
classic/standalone mode and there is a section of unneeded duplicate code
from what I can see. In thinclient mode the daemon would get it own
shutdown message from the OS and deal with it as it does currently.

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:9>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Deluge
2018-03-05 23:22:02 UTC
Permalink
#3011: Listen to WM_ENDSESSION on Windows
------------------------------+--------------------
Reporter: joeyvh | Owner:
Type: feature-request | Status: new
Priority: minor | Milestone: 1.3.16
Component: GTK UI | Version: 1.3.14
Resolution: | Keywords:
------------------------------+--------------------

Comment (by DjLegolas):

Ok, took some time but I finally tested it in a VM, and it halts the
shutdown.[[BR]]
But, still need to test this in some real-world env, as I only tested it
while creating a torrent to simulate a long operation when the signals are
being sent to Deluge by windows.[[BR]][[BR]]
In addition, It seem as when in thinclient, the daemon does not handles
the message at all.[[BR]]
This update can be found in
[https://github.com/DjLegolas/deluge/commit/360c37eb98b1f91a96ed50a65e492e4ac8684a85
this commit].[[br]][[br]]
Notes:
* I removed `WM_ENDSESSION` handler.
* I removed the duplicate code of the method `quit_gtkui`.
* `quit_gtkui` is now a static method -
`MainWindow._quit_gtkui(shutdown)`.
* The new API's `ShutdownBlockReasonDestroy` function is now being called
when the `gtkui` is shuting down.
* '''Most important''': while testing, I noticed that after 1 minute,
Windows shutdown is be cancelled - but `Deluge` will continue with it's
shutdown and eventually close. Therefor, I can use some statistics
regarding the amount of time it usually takes to close `deluge`.

--
Ticket URL: <http://dev.deluge-torrent.org/ticket/3011#comment:10>
Deluge <http://deluge-torrent.org/>
Deluge Project
--
You received this message because you are subscribed to the Google Groups "Deluge Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deluge-dev+***@googlegroups.com.
To post to this group, send email to deluge-***@googlegroups.com.
Visit this group at https://groups.google.com/group/deluge-dev.
For more options, visit https://groups.google.com/d/optout.
Loading...