Got started on a worker process
This commit is contained in:
parent
3d6ae21a7d
commit
82999e37f8
35
TimeWaster.py
Normal file
35
TimeWaster.py
Normal 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()
|
@ -1,5 +1,5 @@
|
|||||||
from websockets import *
|
from websockets import *
|
||||||
import asyncio, json, signal, sys, time, random
|
import asyncio, json, signal, sys, time, random, subprocess, os
|
||||||
|
|
||||||
class WebSocketServer:
|
class WebSocketServer:
|
||||||
server: Server = None
|
server: Server = None
|
||||||
@ -17,6 +17,8 @@ class WebSocketServer:
|
|||||||
|
|
||||||
async def handleConnection(self, connection: ServerConnection) -> None: #TODO: Make this actually do something
|
async def handleConnection(self, connection: ServerConnection) -> None: #TODO: Make this actually do something
|
||||||
print(f"{connection.remote_address} Connected")
|
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
|
connected: bool = True
|
||||||
task: asyncio.Task = None
|
task: asyncio.Task = None
|
||||||
while (connected):
|
while (connected):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user