1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- # coding:utf-8
- from a2s.a2s_server import watch
- from a2s.a2s_client import a2s_execute
- import multiprocessing
- import random
- from concurrent.futures import ThreadPoolExecutor
- import time
- def start_test2img(data):
- # 本次不使用SSL,所以channel是不安全的
- try:
- for t in range(5):
- result = a2s_execute("192.168.3.240:9090", "test2img", 240, b"test")
- result = result.decode("utf-8")
- return result
- except Exception as e:
- print("test2img异常::",e)
- return ""
- @watch
- def run(data: bytes, *args, **kwargs):
- # 是否有图片
- a = random.randint(1, 2)
- print("picture:::>", a)
- if a == 1:
- # 有几张图片
- picture_num = random.randint(2, 40)
- pictures = [i for i in range(picture_num)]
- with ThreadPoolExecutor(max_workers=30) as executor:
- result = executor.map(start_test2img, pictures)
- list(result)
- a = random.randint(5, 20)
- time.sleep(a)
- return data
- def worker():
- run(nats_host="192.168.3.240", nats_port=19090, subject="test2txt", queue="main")
- def add_file_process():
- new_process = multiprocessing.Process(target=worker)
- new_process.start()
- return new_process
|