Разрешение отклонено при загрузке ножей

Основываясь на приведенном здесь ответе, я изменил сценарий @Jacob Vlijm следующим образом, чтобы предотвратить приостановку Ubuntu при любой загрузке или загрузке. Сначала вы должны установить xprintidle.

#!/usr/bin/env python3
#install xprintidle first, it is a binary written in C; see  https://packages.debian.org/sid/xprintidle 
#This script is for prevent/supersede suspend while a download/upload in progress.
#Change wlan0 (wifi) to eth0 (ethernet) or use both if its applies. 
#add it to your startup applications: Dash > Startup Applications > add the command: python3 /path/to/delay_suspend.py
import subprocess
import time
time.sleep(15)
subprocess.Popen(['notify-send', "Ubuntu will supersede suspend while a download/upload in progress"])    

#--- set suspend time below (seconds)
suspend_wait = 300
#---

#--- you can change values below, but I'd leave them as they are
speed_limit = 1000      # set a minimum speed (bytes/looptime) to be considered a download activity
looptime = 20       # time interval between checks
download_wait = 300  # time (seconds) to wait after the last download activity before suspend is re- activated
#---

rx_speed=0
tx_speed=0
speed=0
idletime = 2

t = 0
key = ["gsettings", "get", "org.gnome.settings-daemon.plugins.power", "sleep-inactive-ac-timeout", "set"]

set_suspend = key[0]+" "+key[-1]+" "+(" ").join(key[2:4])
get_suspend = (" ").join(key[0:4])

def get_size():
    return int(subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8").split()[0])

def get(cmd):
    return subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")



def get_bytes(t, iface='wlan0'):
    with open('/sys/class/net/' + iface + '/statistics/' + t + '_bytes', 'r') as f:
        data = f.read();
    return int(data)

if __name__ == '__main__':
    (tx_prev, rx_prev) = (0, 0)
#Rx stand for received (download) and Tx for tranferred (upload).
    while(True):
        tx = get_bytes('tx')
        rx = get_bytes('rx')

        if tx_prev > 0:
            tx_speed = tx - tx_prev


        if rx_prev > 0:
            rx_speed = rx - rx_prev


        time.sleep(looptime)

        tx_prev = tx
        rx_prev = rx

        speedrx =rx_speed/looptime
        #print('RX: ', rx_speed, 'xxxxx')
        speedtx = tx_speed/looptime
        if speedtx > speedrx:
            speed = speedtx
        else:
            speed = speedrx


    # check current suspend setting
        suspend = get(get_suspend).strip()
        idletime = float(subprocess.check_output('xprintidle').strip())
        idletime=idletime/1000
        if speed > speed_limit:
            # check/set disable suspend if necessary
            if suspend != "0":
                subprocess.Popen(["/bin/bash", "-c", set_suspend+" 0"])

            if idletime >  download_wait-2*looptime:
                subprocess.Popen(['notify-send', "Postponed suspend due to active net traffic"]) 
                    #subprocess.Popen(['notify-send', str(speed) +"Postponed suspend for completion of active upload/download"+ str(speed_limit)])  
            t = 0
        else:
            if all([t > download_wait/looptime, suspend != str(download_wait)]):
                # check/enable suspend if necessary
                subprocess.Popen(["/bin/bash", "-c", set_suspend+" "+str(suspend_wait)])

        t = t+1
        #print(idletime)
        #print(speed)
        #print(speed_limit)        
        #subprocess.Popen(['notify-send', str(idletime)])
        #print('speed:', speed)
        #print('speed limit:', speed_limit)
0
задан 24 October 2017 в 06:10

0 ответов

Другие вопросы по тегам:

Похожие вопросы: