简体   繁体   English

打开谷歌电子表格文档时,如何从总是执行的无限循环中停止谷歌应用程序脚本?

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

I was trying to implement an improved solution of the google script suggested here: Script to Change Row Color when a cell changes text .我试图实现此处建议的 google 脚本的改进解决方案: Script to Change Row Color when a cell changes text

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?你有办法解决这个阻塞问题吗?

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() .更新:经过进一步调查,问题的原因似乎是由于从事件触发器onOpen()的无限循环脚本。 So my question can be reformulated to:所以我的问题可以重新表述为:

How do you stop a Google Apps script that gets into an infinite loop?如何停止进入无限循环的 Google Apps 脚本?

Can I use another script to kill the execution of this erroneous script ?我可以使用另一个脚本来终止这个错误脚本的执行吗?

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.在右侧,您有三个点菜单,您可以在其中终止正在运行的项目。

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.然后,当您想停止它时,请连接一个脚本以将全局 var 设置为 false 到按钮图像。 Like this:像这样:

var RUNLOOP = true;

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

function stopLoop() {
  RUNLOOP = false;
}

There is a limit of about 6 minutes beyond which a script will stop executing.脚本将停止执行约 6 分钟的限制。 This is applicable to functions run on a trigger.这适用于在触发器上运行的函数。 But it is definitely worth waiting 6 minutes with your spreadsheet open.但是,在打开电子表格的情况下等待 6 分钟绝对值得。

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.如果您有权访问浏览器历史记录,请使用它来访问项目的代码。

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.使用安装脚本的帐户,找到脚本(使用名称)并将其删除,使其不再工作 - 此操作将删除授予脚本的所有权限。

I had the same question, and here is what I've been able to find:我有同样的问题,这是我能够找到的:

The script will eventually time out after 6 minutes .该脚本最终将在 6 分钟后超时 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.目前,您只能在脚本编辑器中手动停止正在运行的 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-executionhttps://ctrlq.org/code/20112-suspend-google-script-execution

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从部署为网络应用的Google应用脚本中打开电子表格 - How to open spreadsheet from Google app script deployed as web app Google App脚本电子表格 - Google App Script Spreadsheet 如何将 Ajax 中的数组值插入 Google App 脚本电子表格 - How to Insert Array Value from Ajax into Google App Script Spreadsheet 将 json/csv 文件(从 API 获取)保存到电子表格文档而不使用循环 - Google Apps 脚本 - Save a json/csv file (fetched from an API) to a spreadsheet document without using a loop - Google Apps Script Google App Script/Javascript - 无法使用 Google App Script 循环到 Google 电子表格中的列末尾 - Google App Script/Javascript - Not able to loop through up to the end of Column in Google Spreadsheet using Google App Script 绑定到电子表格的Google App脚本 - Google App Script Bounded to Spreadsheet 如何使用Google App脚本中的JavaScript从Google电子表格数据库中获取日期值 - How do i get the date value from google spreadsheet database using javascript in google app script 从Google电子表格发送带有脚本的电子邮件-Need Loop - Sending email with script from Google spreadsheet - need loop 如何使用谷歌应用脚本将一行从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy a row from one google spreadsheet to another google spreadsheet using google apps script? 如何阻止 Google App Script 复制副本? - How to stop Google App Script is duplicating copies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM