Skip to content

Commit 02b8029

Browse files
authored
Merge pull request #64 from bEpic-studio/enhancement/close-ayonmenus-when-dvr-is-shutdown
Close AYON Menus when Resolve is shutdown
2 parents 2c6c290 + ae9533c commit 02b8029

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

client/ayon_resolve/api/menu.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from ayon_core.style import load_stylesheet
99
from ayon_core.resources import get_ayon_icon_filepath
1010

11+
from .pulse import PulseThread
12+
1113
MENU_LABEL = os.environ["AYON_MENU_LABEL"]
1214

1315

@@ -143,7 +145,6 @@ def on_set_resolution_clicked(self):
143145
print("Clicked Set Resolution")
144146

145147

146-
147148
def launch_ayon_menu():
148149
app = (
149150
QtWidgets.QApplication.instance()
@@ -157,4 +158,9 @@ def launch_ayon_menu():
157158

158159
ayon_menu.show()
159160

161+
# Force close current process if Resolve is closed
162+
pulse = PulseThread(parent=ayon_menu)
163+
pulse.no_host_response.connect(app.quit)
164+
pulse.start()
165+
160166
sys.exit(app.exec_())

client/ayon_resolve/api/pulse.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""This module is a copy from ayon-resolve"""
2+
3+
import os
4+
import sys
5+
6+
from qtpy import QtCore
7+
8+
9+
class PulseThread(QtCore.QThread):
10+
"""A Timer that checks whether host app is still alive.
11+
12+
This checks whether the Resolve process is still active at a certain
13+
interval. This is useful due to how Resolve runs its scripts. Each script
14+
runs in its own environment and process (a `fusionscript` process each).
15+
If Resolve would go down and we have a UI process running at the same time
16+
then it can happen that the `fusionscript.exe` will remain running in the
17+
background in limbo due to e.g. a Qt interface's QApplication that keeps
18+
running infinitely.
19+
20+
Warning:
21+
When the host is not detected this will automatically exit
22+
the current process.
23+
"""
24+
no_host_response = QtCore.Signal()
25+
26+
def __init__(self, parent=None):
27+
super(PulseThread, self).__init__(parent=parent)
28+
29+
def run(self):
30+
app = getattr(sys.modules["__main__"], "app", None)
31+
32+
# Interval in milliseconds
33+
interval = int(os.environ.get("AYON_RESOLVE_PULSE_INTERVAL", 1000))
34+
35+
while True:
36+
if self.isInterruptionRequested():
37+
return
38+
39+
# We don't need to call Test because PyRemoteObject of the app
40+
# will actually fail to even resolve the Test function if it has
41+
# gone down. So we can actually already just check by confirming
42+
# the method is still getting resolved. (Optimization)
43+
if app.Test is None:
44+
self.no_host_response.emit()
45+
46+
self.msleep(interval)

0 commit comments

Comments
 (0)