1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-06-13 12:54:14 +00:00

Scribunto: Hack fix for stopping long-running threads [#737]

This commit is contained in:
gnosygnu 2020-06-15 10:18:34 -04:00
parent b4516f5060
commit b87e4d07cb
3 changed files with 72 additions and 43 deletions

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0. or alternatively under the terms of the Apache License Version 2.0.
@ -13,8 +13,17 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.threads; import gplx.*; import gplx.core.*; package gplx.core.threads;
import java.lang.*;
import gplx.Cancelable;
import gplx.Cancelable_;
import gplx.Err_;
import gplx.GfoMsg;
import gplx.GfoMsg_;
import gplx.Gfo_invk;
import gplx.Gfo_invk_;
import gplx.Gfo_log_;
public class Thread_adp implements Runnable { public class Thread_adp implements Runnable {
private final String thread_name; private final Cancelable cxl; private final boolean cxlable; private final String thread_name; private final Cancelable cxl; private final boolean cxlable;
private final Gfo_invk invk_itm; private final String invk_cmd; private final GfoMsg invk_msg; private final Gfo_invk invk_itm; private final String invk_cmd; private final GfoMsg invk_msg;
@ -28,6 +37,7 @@ public class Thread_adp implements Runnable {
public boolean Thread__cancelable() {return cxlable;} public boolean Thread__cancelable() {return cxlable;}
public boolean Thread__is_alive() {return thread == null ? false : thread.isAlive();} public boolean Thread__is_alive() {return thread == null ? false : thread.isAlive();}
public void Thread__interrupt() {thread.interrupt();} public void Thread__interrupt() {thread.interrupt();}
public void Thread__stop() {thread.stop();}
public void run() { public void run() {
try { try {
Gfo_invk_.Invk_by_msg(invk_itm, invk_cmd, invk_msg); Gfo_invk_.Invk_by_msg(invk_itm, invk_cmd, invk_msg);

View File

@ -1,6 +1,6 @@
/* /*
XOWA: the XOWA Offline Wiki Application XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com Copyright (C) 2012-2020 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3, XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0. or alternatively under the terms of the Apache License Version 2.0.
@ -13,7 +13,15 @@ The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/ */
package gplx.core.threads; import gplx.*; import gplx.core.*; package gplx.core.threads;
import gplx.Cancelable;
import gplx.Cancelable_;
import gplx.Err_;
import gplx.GfoMsg;
import gplx.GfoMsg_;
import gplx.Gfo_invk;
public class Thread_adp_ { public class Thread_adp_ {
public static void Sleep(int milliseconds) { public static void Sleep(int milliseconds) {
try { try {

View File

@ -24,6 +24,7 @@ import gplx.xowa.wikis.nss.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.tmpls.*; import gplx.xowa.parsers.*; import gplx.xowa.parsers.logs.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.xtns.pfuncs.*; import gplx.xowa.xtns.pfuncs.*;
public class Scrib_invoke_func extends Pf_func_base { public class Scrib_invoke_func extends Pf_func_base {
@Override public int Id() {return Xol_kwd_grp_.Id_invoke;} @Override public int Id() {return Xol_kwd_grp_.Id_invoke;}
@Override public Pf_func New(int id, byte[] name) {return new Scrib_invoke_func().Name_(name);} @Override public Pf_func New(int id, byte[] name) {return new Scrib_invoke_func().Name_(name);}
@ -72,11 +73,15 @@ public class Scrib_invoke_func extends Pf_func_base {
InvokeInvoker invoker = new InvokeInvoker(core, wiki, ctx, src, caller, self, bfr, mod_name, mod_raw, fnc_name); InvokeInvoker invoker = new InvokeInvoker(core, wiki, ctx, src, caller, self, bfr, mod_name, mod_raw, fnc_name);
Thread_adp thread = Thread_adp_.Start_by_key("scribunto", invoker, "default"); Thread_adp thread = Thread_adp_.Start_by_key("scribunto", invoker, "default");
while (thread.Thread__is_alive()) { while (thread.Thread__is_alive()) {
Thread_adp_.Sleep(10);
if (System_.Ticks__elapsed_in_frac(timeBgn) > timeoutInMs) { if (System_.Ticks__elapsed_in_frac(timeBgn) > timeoutInMs) {
thread.Thread__interrupt(); thread.Thread__stop();
throw Err_.new_wo_type(String_.Format("scribunto timeout: page={0} mod={1} func={2} time={3}", ctx.Page_url_str(), mod_name, fnc_name, timeoutInMs)); invoker.Exc = Err_.new_wo_type(String_.Format("scribunto timeout: page={0} mod={1} func={2} time={3}", ctx.Page_url_str(), mod_name, fnc_name, timeoutInMs));
} }
} }
if (invoker.Exc != null) {
throw invoker.Exc;
}
if (invoke_wkr != null) if (invoke_wkr != null)
invoke_wkr.Eval_end(ctx.Page(), mod_name, fnc_name, log_time_bgn); invoke_wkr.Eval_end(ctx.Page(), mod_name, fnc_name, log_time_bgn);
} }
@ -131,8 +136,14 @@ public class Scrib_invoke_func extends Pf_func_base {
this.mod_raw = mod_raw; this.mod_raw = mod_raw;
this.fnc_name = fnc_name; this.fnc_name = fnc_name;
} }
public Exception Exc;
public Object Invk(GfsCtx gctx, int ikey, String k, GfoMsg m) { public Object Invk(GfsCtx gctx, int ikey, String k, GfoMsg m) {
try {
core.Invoke(wiki, ctx, src, caller, self, bfr, mod_name, mod_raw, fnc_name); core.Invoke(wiki, ctx, src, caller, self, bfr, mod_name, mod_raw, fnc_name);
}
catch (Exception exc) {
this.Exc = exc;
}
return null; return null;
} }
} }