andyye03 Posted May 9, 2020 Posted May 9, 2020 I tried to use subprocess as a way to continuously run a python script even after closing the browser, using the start and stop pages on https://flazepe.gitbook.io/heliohost/tutorials/discord-botBut no matter how long I waited, the script only ran when the "start" page was open, and when I tried to stop the script, it told me that there was no script to stop. my start script is #!/usr/bin/python3.7print("Content-Type: text/html\n\n")import os, subprocess, signalcounter = 0p = subprocess.Popen(['ps', '-u', 'andyye03'], stdout=subprocess.PIPE)# must match your username --------^^^^^^^^out, err = p.communicate()for line in out.splitlines(): if 'gaonnuriallimi.py'.encode('utf-8') in line:# ^^^^^^^^^^^----- this has to match the filename of your bot script counter += 1 print("Bot already running.")if counter == 0: subprocess.Popen("/home/andyye03/gaonnuriallimi.py")# ^^^^^^^^-- be sure to update it to your username print("Bot started!") and my stop script is #!/usr/bin/python3.7import os, subprocess, signalprint("Content-Type: text/html\n\n")counter = 0p = subprocess.Popen(['ps', '-u', 'andyye03'], stdout=subprocess.PIPE)# must match your username --------^^^^^^^^out, err = p.communicate()for line in out.splitlines(): if 'gaonnuriallimi.py'.encode('utf-8') in line:# ^^^^^^^--- this has to match the filename of your loop counter += 1 pid = int(line.split(None, 1)[0]) print("Stopping bot.") os.kill(pid, signal.SIGTERM)if counter == 0: print("Already stopped.")
Krydos Posted May 9, 2020 Posted May 9, 2020 the script only ran when the "start" page was openThat's funny, because you have >>>5<<< of them running at once right now: # ps aux | grep -v grep | grep andyye03 andyye03 1863 0.2 0.2 272596 45280 ? S 15:45 0:08 /usr/bin/python3.7 /home/andyye03/public_html/cgi-bin/gaonnuriallimi.py andyye03 8600 0.2 0.2 270036 42480 ? S 15:50 0:07 /usr/bin/python3.7 /home/andyye03/public_html/cgi-bin/gaonnuriallimi.py andyye03 22318 0.3 0.2 268244 41036 ? S 15:44 0:09 /usr/bin/python3.7 /home/andyye03/public_html/cgi-bin/gaonnuriallimi.py andyye03 23821 0.2 0.2 272600 45068 ? S 15:46 0:08 /usr/bin/python3.7 /home/andyye03/public_html/cgi-bin/gaonnuriallimi.py andyye03 25727 0.2 0.2 266092 38652 ? S 15:56 0:06 /usr/bin/python3.7 /home/andyye03/gaonnuriallimi.py I'll kill them for you.
andyye03 Posted May 10, 2020 Author Posted May 10, 2020 Oh shit sorry I didn't realize that they were runningmust be a problem with my stop script
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now