Got started on a worker process

This commit is contained in:
nc5432 2025-10-07 13:02:52 -04:00
parent 3d6ae21a7d
commit 82999e37f8
2 changed files with 38 additions and 1 deletions

35
TimeWaster.py Normal file
View File

@ -0,0 +1,35 @@
import time, uuid, signal, random, os
class TimeWaster:
def __init__(self):
self.running = True
self.jobs: dict = {}
def handleNewJob(self):
jobId: uuid.UUID = uuid.uuid4()
self.jobs[jobId] = "exists i guess"
def handleCancelJob(self):
pass
def quit(self):
self.running = False
def main(self):
while self.running:
if len(self.jobs) == 0:
time.sleep(0.01)
else:
uuid = self.jobs.keys[0]
job = self.jobs[uuid]
time.sleep(random.randrange(1, 10) / 10)
result: JobResult = JobResult(uuid, "done i guess")
os.write(1, result)
class JobResult:
def __init__(self, uuid, result) -> None:
self.uuid = uuid
self.result = result
if __name__ == "__main__":
TimeWaster().main()

View File

@ -1,5 +1,5 @@
from websockets import *
import asyncio, json, signal, sys, time, random
import asyncio, json, signal, sys, time, random, subprocess, os
class WebSocketServer:
server: Server = None
@ -17,6 +17,8 @@ class WebSocketServer:
async def handleConnection(self, connection: ServerConnection) -> None: #TODO: Make this actually do something
print(f"{connection.remote_address} Connected")
stdio: tuple(int, int) = os.pipe2()
worker: subprocess.Popen = subprocess.Popen(["python3", "TimeWaster.py"], stdin=stdio[0], stdout=stdio[1])
connected: bool = True
task: asyncio.Task = None
while (connected):