是否有一种方法以编程方式防止谷歌Colab超时断开?

笔记本电脑自动断开连接的情况如下:

谷歌Colab笔记本的空闲超时为90分钟,绝对超时为12小时。这意味着,如果用户没有与他的谷歌Colab笔记本进行交互超过90分钟,其实例将自动终止。此外,Colab实例的最大生存期为12小时。

自然,我们希望自动地从实例中挤出最大的值,而不必不断地手动与它交互。这里我将假设常见的系统需求:

Ubuntu 18.04 LTS (Bionic Beaver), Windows 10或Mac操作系统 对于基于linux的系统,使用流行的桌面环境,如GNOME 3或Unity Firefox或Chromium浏览器

我应该在这里指出,这样的行为并不违反谷歌Colab的使用条款,尽管根据他们的常见问题解答,这是不鼓励的(简而言之:从道德上讲,如果你真的不需要它,那么用完所有的gpu是不可以的)。


我目前的解决方案非常愚蠢:

首先,我把屏保关掉,这样我的屏幕就一直开着。 我有一个Arduino板,所以我只是把它变成了一个橡胶鸭子USB设备,让它在我睡觉的时候模拟原始的用户交互(只是因为我手头有其他用例)。

有没有更好的办法?


当前回答

这对我来说很管用:

函数ClickConnect () { console.log(“工作”); document.querySelector(“paper-icon-button”).click () } Const myjob = setInterval(点击连接,60000)

如果不工作,试着通过运行:

clearInterval (myjob)

其他回答

使用Python和Selenium:

from selenium.webdriver.common.keys import Keys
from selenium import webdriver
import time

driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver')

notebook_url = ''
driver.get(notebook_url)

# run all cells
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.F9)
time.sleep(5)

# click to stay connected
start_time = time.time()
current_time = time.time()
max_time = 11*59*60 #12hours

while (current_time - start_time) < max_time:
    webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
    driver.find_element_by_xpath('//*[@id="top-toolbar"]/colab-connect-button').click()
    time.sleep(30)
    current_time = time.time()
var startColabHandler = function startColabHandler(interval = 60000, enableConnectButton = false) {
    console.log("colabHandler - configure - start: " + new Date());
    
    var colabClick = function colabClick() {
        console.log("colabHandler - click - start: " + new Date());
        
        if (enableConnectButton === true) {
            var button1 = document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect");
            
            if (button1) {
                button1.click()
            }
        }
        
        button2 = document.querySelector("html body colab-dialog.yes-no-dialog paper-dialog div.buttons paper-button#ok");
        
        if (button2) {
            button2.click()
        }
        
        console.log("colabHandler - click - end: " + new Date());
    };

    var intervalId = setInterval(colabClick, interval);

    window.stopColabHandler = function stopColabHandler() {
        console.log("colabHandler - stop - start: " + new Date());
        
        clearInterval(intervalId);
        
        console.log("colabHandler - stop - start: " + new Date());
    };

    console.log("colabHandler - configure - end: " + new Date());
};

试试这个:

function ClickConnect(){
  console.log("Working"); 
  document
    .querySelector("#top-toolbar > colab-connect-button")
    .shadowRoot
    .querySelector("#connect")
    .click()
}

setInterval(ClickConnect,60000)

好吧,我不是一个Python人,我也不知道这个“Colab”的实际用途是什么。我把它作为一个构建系统,哈哈。我曾经在里面设置ssh转发,然后放这个代码,让它运行,是的,它可以工作。

import getpass
authtoken = getpass.getpass()

当所有这些都失败时,您可以通过订阅谷歌Colab Pro+获得后台执行