Skip to content

Commit

Permalink
exit AHK daemon process if parent Python process exits unexpectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
spyoungtech committed Feb 6, 2024
1 parent 84e8ab3 commit 859161b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ahk/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2756,6 +2756,7 @@
{% endfor %}
; END extension scripts
{% block before_autoexecute %}
{% endblock before_autoexecute %}
Expand All @@ -2765,6 +2766,15 @@
Loop {
query := RTrim(stdin.ReadLine(), "`n")
if (query = "") {
; Technically this should only happen if the Python process has died, so sending a message is probably futile
; But if this somehow triggers in some other case, we'll try to have an informative error raised.
pyresp := FormatResponse("ahk.message.ExceptionResponseMessage", "Unexpected empty message; AHK exiting. This is likely a bug. Please report this issue at https://github.com/spyoungtech/ahk/issues")
FileAppend, %pyresp%, *, UTF-8
; Exit to avoid leaving the process hanging around needlessly
ExitApp
}
argsArray := CommandArrayFromQuery(query)
try {
func := argsArray[1]
Expand Down Expand Up @@ -5744,6 +5754,15 @@
Loop {
query := RTrim(stdin.ReadLine(), "`n")
if (query = "") {
; Technically, this should only happen if the Python process has died, so sending a message is probably futile
; But if this somehow triggers in some other case and the Python process is still listening, we'll try to have an informative error raised.
pyresp := FormatResponse("ahk.message.ExceptionResponseMessage", "Unexpected empty message; AHK exiting. This is likely a bug. Please report this issue at https://github.com/spyoungtech/ahk/issues")
stdout.Write(pyresp)
stdout.Read(0)
; Exit to avoid leaving the process hanging around
ExitApp
}
argsArray := CommandArrayFromQuery(query)
try {
func_name := argsArray[1]
Expand Down
9 changes: 9 additions & 0 deletions ahk/templates/daemon-v2.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -2845,6 +2845,15 @@ pyresp := ""

Loop {
query := RTrim(stdin.ReadLine(), "`n")
if (query = "") {
; Technically, this should only happen if the Python process has died, so sending a message is probably futile
; But if this somehow triggers in some other case and the Python process is still listening, we'll try to have an informative error raised.
pyresp := FormatResponse("ahk.message.ExceptionResponseMessage", "Unexpected empty message; AHK exiting. This is likely a bug. Please report this issue at https://github.com/spyoungtech/ahk/issues")
stdout.Write(pyresp)
stdout.Read(0)
; Exit to avoid leaving the process hanging around
ExitApp
}
argsArray := CommandArrayFromQuery(query)
try {
func_name := argsArray[1]
Expand Down
10 changes: 10 additions & 0 deletions ahk/templates/daemon.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,7 @@ CommandArrayFromQuery(ByRef text) {

{% endfor %}
; END extension scripts

{% block before_autoexecute %}
{% endblock before_autoexecute %}

Expand All @@ -2762,6 +2763,15 @@ pyresp := ""

Loop {
query := RTrim(stdin.ReadLine(), "`n")
if (query = "") {
; Technically this should only happen if the Python process has died, so sending a message is probably futile
; But if this somehow triggers in some other case, we'll try to have an informative error raised.
pyresp := FormatResponse("ahk.message.ExceptionResponseMessage", "Unexpected empty message; AHK exiting. This is likely a bug. Please report this issue at https://github.com/spyoungtech/ahk/issues")
FileAppend, %pyresp%, *, UTF-8

; Exit to avoid leaving the process hanging around needlessly
ExitApp
}
argsArray := CommandArrayFromQuery(query)
try {
func := argsArray[1]
Expand Down

0 comments on commit 859161b

Please sign in to comment.