Fixing asyncio issues in webapp (#347)

Co-authored-by: Dave <dbisu>
This commit is contained in:
Dave
2026-03-18 11:10:50 -05:00
committed by GitHub
parent 58875cd1b6
commit e087a69da9
2 changed files with 9 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
# License : GPLv2.0 # License : GPLv2.0
# copyright (c) 2023 Dave Bailey # copyright (c) 2026 Dave Bailey
# Author: Dave Bailey (dbisu, @daveisu) # Author: Dave Bailey (dbisu, @daveisu)
# #
# TODO: ADD support for the following: # TODO: ADD support for the following:
@@ -298,7 +298,7 @@ async def parseLine(line, script_lines):
print(f"Unknown key to RELEASE: <{key}>") print(f"Unknown key to RELEASE: <{key}>")
elif(line[0:5] == "DELAY"): elif(line[0:5] == "DELAY"):
line = replaceVariables(line) line = replaceVariables(line)
time.sleep(float(line[6:])/1000) await asyncio.sleep(float(line[6:])/1000)
elif line == "STRINGLN": #< stringLN block elif line == "STRINGLN": #< stringLN block
line = next(script_lines).strip() line = next(script_lines).strip()
line = replaceVariables(line) line = replaceVariables(line)
@@ -495,7 +495,7 @@ async def runScript(file):
for i in range(int(line[7:])): for i in range(int(line[7:])):
#repeat the last command #repeat the last command
parseLine(previousLine, script_lines) parseLine(previousLine, script_lines)
time.sleep(float(defaultDelay) / 1000) await asyncio.sleep(float(defaultDelay) / 1000)
elif line.startswith("RESTART_PAYLOAD"): elif line.startswith("RESTART_PAYLOAD"):
restart = True restart = True
break break
@@ -505,7 +505,7 @@ async def runScript(file):
else: else:
await parseLine(line, script_lines) await parseLine(line, script_lines)
previousLine = line previousLine = line
time.sleep(float(defaultDelay) / 1000) await asyncio.sleep(float(defaultDelay) / 1000)
except OSError as e: except OSError as e:
print("Unable to open file", file) print("Unable to open file", file)

View File

@@ -7,6 +7,7 @@ import socketpool
import time import time
import os import os
import storage import storage
import asyncio
import wsgiserver as server import wsgiserver as server
from adafruit_wsgi.wsgi_app import WSGIApp from adafruit_wsgi.wsgi_app import WSGIApp
@@ -225,11 +226,11 @@ def delete(request, filename):
return("200 OK",[('Content-Type', 'text/html')], response) return("200 OK",[('Content-Type', 'text/html')], response)
@web_app.route("/run/<filename>") @web_app.route("/run/<filename>")
def run_script(request, filename): async def run_script(request, filename):
print("run_script ", filename) print("run_script ", filename)
response = response_html.format("Running script " + filename) response = response_html.format("Running script " + filename)
#print(response) #print(response)
runScript(filename) await runScript(filename)
return("200 OK",[('Content-Type', 'text/html')], response) return("200 OK",[('Content-Type', 'text/html')], response)
@web_app.route("/") @web_app.route("/")
@@ -238,12 +239,12 @@ def index(request):
return("200 OK", [('Content-Type', 'text/html')], response) return("200 OK", [('Content-Type', 'text/html')], response)
@web_app.route("/api/run/<filenumber>") @web_app.route("/api/run/<filenumber>")
def run_script(request, filenumber): async def run_script(request, filenumber):
filename = setPayload(int(filenumber)) filename = setPayload(int(filenumber))
print("run_script ", filenumber) print("run_script ", filenumber)
response = response_html.format("Running script " + filename) response = response_html.format("Running script " + filename)
#print(response) #print(response)
runScript(filename) await runScript(filename)
return("200 OK",[('Content-Type', 'text/html')], response) return("200 OK",[('Content-Type', 'text/html')], response)
async def startWebService(): async def startWebService():