#!/usr/bin/env python
import _thread
import asyncio
import json
import subprocess
import asyncio
import time
import websockets
import multiprocessing
import asyncio
import websockets
process = []
def run_chrome(num, command):
for i in (0, num):
child = subprocess.Popen(command)
pid = child.pid
process.append({pid: child})
print(pid)
print(process)
child.wait()
async def hello():
uri = "ws://localhost:8080"
async with websockets.connect(uri) as websocket:
j = json.dumps(
{
"TOKEN": "A-asdasd",
"ACTION": "RIGISTER",
"IP": "127.0.0.1"
})
print(j)
await websocket.send(j)
while True:
json_receive = await websocket.recv()
try:
if json.loads(json_receive)['TYPE'] == "RUN":
print("运行")
except Exception as e:
print(e)
print('收到指令:', json_receive)
# run_chrome(1,["python3", "/Users/interface/Desktop/amazon/youtube.py"])
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(hello())