handling cpu limiting differently, maybe fine

This commit is contained in:
jenz
2025-06-05 23:46:59 +02:00
parent d988a4ffcb
commit aa9785da5a
2 changed files with 10 additions and 15 deletions
+8 -12
View File
@@ -164,17 +164,16 @@ def bot_connect(data):
#use whatever ip you want here to connect with
str1 = ""
if "connect to ze" == data:
str1 = f"connect {data_ports['server_ip_port_ze']}"
str1 = f"connect {data_ports['server_ip_port_ze']};"
elif "connect to ze2" == data:
str1 = f"connect {data_ports['server_ip_port_ze2']}; wait 15000;"
str1 = f"connect {data_ports['server_ip_port_ze2']};" #wait 15000;
writeCfgInput(str1)
time.sleep(1)
def cpulimit_pid_of_game():
# ' > /dev/null' redirects stdout to /dev/null
# '2>&1' redirects stderr to the same place as stdout
pid = return_user_owned_pid("pidof cstrike_linux64")
cmd = f"cpulimit --pid={pid} --limit=5 --background > /dev/null 2>&1"
cmd = f"cpulimit --pid={pid} --limit=35 --background > /dev/null 2>&1"
subprocess.Popen([cmd], shell=True, stdout=subprocess.PIPE).communicate()[0]
def delete_lock_file():
@@ -188,10 +187,7 @@ def my_file_created_function(event_path):
file_size = None
while True:
#repeatedly spamming to kill cpu limitting, its bottlenecking the download speed
kill_owned_process("pidof cpulimit")
time.sleep(10)
stdout, stderr = subprocess.Popen(["ls", "-l", event_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
#print('stdout: ', stdout)
#print('stderr: ', stderr)
@@ -206,6 +202,7 @@ def my_file_created_function(event_path):
#in case the bz2 download is not progressing just delete the file and disconnect.
cur_file_size = stdout.decode().split("autismbots")[1].strip().split(" ")[0]
print('cur_file_size: ', cur_file_size, ' stdout decode: ', stdout.decode())
if file_size == cur_file_size:
print("Aborting connection. file download is stuck.")
writeCfgInput("disconnect;")
@@ -265,6 +262,7 @@ if __name__ == '__main__':
print("launching game...")
fail_safe -= 1
time.sleep(10)
cpulimit_pid_of_game()
try:
while True:
@@ -297,14 +295,14 @@ if __name__ == '__main__':
print('bot kicked server full: ', datetime.datetime.now().time())
elif "autismo connected to ze" == data:
print('Bot connected to ze!')
cpulimit_pid_of_game()
#cpulimit_pid_of_game()
is_bot_connected_to_ze2 = False
overwrite_file_access()
elif "not connected to ze2" == data:
is_bot_connected_to_ze2 = False
elif "autismo connected to ze2" == data:
print('Bot connected to ze2!')
cpulimit_pid_of_game()
#cpulimit_pid_of_game()
is_bot_connected_to_ze2 = True
overwrite_file_access()
elif "connect to ze" == data or ("connect to ze2" == data and not is_bot_connected_to_ze2):
@@ -315,9 +313,7 @@ if __name__ == '__main__':
print('exiting after running the game for several hours.')
sys.exit(1)
else:
#stop cpu limitting, its bottlenecking the connection to the server.
kill_owned_process("pidof cpulimit")
#print('data: ', data)
print('data: ', data)
bot_connect(data)
elif "clientmessage:" in data:
messager_name = data.split("clientmessage:", 1)[1].split(f" {data_ports['magic_secret']}")[0]