Javascript 如何从打开 Google 电子表格文档时始终执行的无限循环中停止 Google 应用程序脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14892906/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 18:15:02  来源:igfitidea点击:

How to stop a google app script from an infinite loop always executed when opening the Google Spreadsheet document?

javascriptgoogle-apps-scriptgoogle-sheets

提问by fabien7474

I was trying to implement an improved solution of the google script suggested here: Google Spreadsheet: Script to Change Row Color when a cell changes text;.

我试图实现此处建议的 google 脚本的改进解决方案:Google 电子表格:当单元格更改文本时更改行颜色的脚本;.

However, after debugging my script, it occurred that my document is not accessible anymore.It seems that my script is erroneous and prevents my document from opening... The consequence is that I cannot disable/edit/remove the associated google script and I am stuck!

但是,在调试我的脚本后,我的文档无法再访问。似乎我的脚本是错误的并且阻止了我的文档打开......结果是我无法禁用/编辑/删除关联的谷歌脚本,我被卡住了!

Do you have a way to solve this blocking issue?

你有办法解决这个阻塞问题吗?

Thanks,

谢谢,

Fabien

法比安

UPDATE:After further investigations, it seems that the reason of the problem is due to an infinite loop script called from the event trigger onOpen(). So my question can be reformulated to:

更新:经过进一步调查,问题的原因似乎是由于从事件触发器 onOpen() 调用的无限循环脚本。所以我的问题可以重新表述为:

How do you stop a Google App script that gets into an infinite loop?

您如何阻止陷入无限循环的 Google App 脚本?

Can I use another script to kill the execution of this erroneous script ?

我可以使用另一个脚本来终止这个错误脚本的执行吗?

回答by lordofmax

This is an old post but just in case:

这是一个旧帖子,但以防万一:

Go to your Google Apps Script project page, within the My Executions tab: https://script.google.com/home/executions.

转到您的 Google Apps 脚本项目页面,在我的执行选项卡中:https://script.google.com/home/executions

Filter by status so you can find the running project. On the right you have the three dots menu where you can terminate the running project.

按状态过滤,以便您可以找到正在运行的项目。在右侧,您有三个点菜单,您可以在其中终止正在运行的项目。

回答by GeneCode

Actually it is very simple. In your script loop, set a global var. Then when you want to stop it, wire up a script to set global var to false to a button image for example. Like this:

其实很简单。在您的脚本循环中,设置一个全局变量。然后当你想停止它时,连接一个脚本来将全局变量设置为 false 到一个按钮图像。像这样:

var RUNLOOP = true;

function YourLoop() {
  if (RUNLOOP) {
     // your code that does something every loop
  }
}

function stopLoop() {
  RUNLOOP = false;
}

回答by Srik

There is a limit of about 6 minutes beyond which a script will stop executing. This is applicable to functions run on a trigger. But it is definitely worth waiting 6 minutes with your spreadsheet open.

脚本将停止执行大约 6 分钟的限制。这适用于在触发器上运行的函数。但是在您的电子表格打开的情况下等待 6 分钟绝对值得。

回答by fooby

When you copy a spreadsheet, triggers created in the triggers menu are removed. Try making a copy of the offending spreadsheet and going from there.

当您复制电子表格时,在触发器菜单中创建的触发器将被删除。尝试复制有问题的电子表格并从那里开始。

If you have access to your browser history, use it to access just the code of your project.

如果您有权访问浏览器历史记录,请使用它来仅访问您的项目代码。

回答by Riyafa Abdul Hameed

You can go to the following address:

您可以前往以下地址:

https://security.google.com/settings/security/permissions

https://security.google.com/settings/security/permissions

using the account on which the script is installed, find the script(using the name) and remove it so that it will no longer work--this action will remove all the permissions given to the script.

使用安装脚本的帐户,找到脚本(使用名称)并将其删除,使其不再工作——此操作将删除授予脚本的所有权限。

回答by Jon Senchyna

I had the same question, and here is what I've been able to find:

我有同样的问题,这是我能够找到的:

The script will eventually time out after 6 minutes. At this time, you can only manually stop an actively running Google Apps Script from within the Script Editor, and even then, only if you kicked it off from within the Script Editor.

脚本最终将在 6 分钟后超时。目前,您只能从 脚本编辑器 中手动停止正在运行的 Google Apps 脚本,即使如此,也必须从脚本编辑器中将其启动。

As a workaround, you can build in a "kill-switch" to your functions, but this might negatively impact performance and will require you to add logic to check the "kill switch" to every function you want to be able to stop.

作为一种解决方法,您可以为您的函数内置一个“终止开关”,但这可能会对性能产生负面影响,并且需要您添加逻辑来检查每个您希望能够停止的函数的“终止开关”。

Here is an example of such a "kill switch":
https://ctrlq.org/code/20112-suspend-google-script-execution

这是此类“终止开关”的示例:https:
//ctrlq.org/code/20112-suspend-google-script-execution