当前位置: 首页 > news >正文

seowhy教研室seo营销论文

seowhy教研室,seo营销论文,做微博这样的网站吗,小程序推广模式和营销方案需求:在Python-主线程控制子线程-3的基础上,新增使用UDP接收指令功能,代替从键盘输入指令 # 修改后的程序,主线程可以获取子线程的结果 import threading import time import queue import tracebackfrom loguru import logger i…

需求:在Python-主线程控制子线程-3的基础上,新增使用UDP接收指令功能,代替从键盘输入指令

# 修改后的程序,主线程可以获取子线程的结果
import threading
import time
import queue
import tracebackfrom loguru import logger
import socketclass WorkerThread(threading.Thread):def __init__(self, result_queue):super().__init__()self.stop_event = threading.Event()self.result_queue = result_queuestatic_variable = 0def run(self):thread_id = threading.get_ident()print(f"Worker thread {thread_id} has started.")while not self.stop_event.is_set():print(f"Worker thread {thread_id} is running.")result = self.do_work()self.result_queue.put(result)time.sleep(1)print(f"Worker thread {thread_id} has stopped.")def increment_static_variable(cls):cls.static_variable += 1def do_work(self):  # Simulate some work# self.increment_static_variable()self.static_variable += 1return self.static_variabledef stop(self):self.stop_event.set()self.join()  # 等待子线程结束class KeyListener:def __init__(self, result_queue_listener):self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)self.address = ("127.0.0.1", 12580)self.server_socket.bind(self.address)self.stop_event = threading.Event()self.result_queue_listener = result_queue_listenerdef udp_recv(self):while not self.stop_event.is_set():try:receive_dat, client_address = self.server_socket.recvfrom(1024)command = receive_dat.decode()print(command)self.result_queue_listener.put(command)except socket.error:# This will be triggered when the socket is closedpassdef start(self):keyboard_thread = threading.Thread(target=self.udp_recv)  # 创建键盘输入监听线程keyboard_thread.start()logger.info(f"Keyboard monitor thread {keyboard_thread.ident} has started~")def stop(self):self.stop_event.set()self.server_socket.close()def end_child_thread():try:if worker_thread.is_alive():worker_thread.stop()logger.info(f"Stopping worker thread {worker_thread.ident}...")if worker_thread.is_alive():logger.info(f"Worker thread {worker_thread.ident} is still active")else:logger.info(f"Worker thread {worker_thread.ident} doesn't exist ..")except Exception as e:logger.info("中止线程失败:" + e)if __name__ == '__main__':result_queue = queue.Queue()result_queue_listener = queue.Queue()main_thread_id = threading.main_thread().identlogger.info(f"Main thread {main_thread_id} has started~")worker_thread = WorkerThread(result_queue)worker_thread.start()logger.info(f"worker thread {worker_thread.ident} has started~")key_listener = KeyListener(result_queue_listener)key_listener.start()exit_program = Falsetry:while not exit_program:if not result_queue_listener.empty():command = result_queue_listener.get()if command == '0':logger.info(f"工作线程状态{worker_thread}")end_child_thread()logger.info(f"工作线程状态{worker_thread}")elif command == '1':try:if worker_thread.is_alive():passelse:worker_thread = WorkerThread(result_queue)worker_thread.start()logger.info(f"Started new worker thread {worker_thread.ident}")except Exception as e:logger.info("新建工作线程失败:" + e)elif command == '2':end_child_thread()key_listener.stop()print(f"停止工作线程{worker_thread}")print(f"停止监听线程{key_listener}")exit_program = Truebreakelse:passtime.sleep(0.1)if not result_queue.empty():result = result_queue.get()print("主线程获取的子线程结果:", result)else:passexcept Exception as e:print("Exception caught:", e)traceback.print_exc()  # 打印详细的异常堆栈信息end_child_thread()key_listener.stop()print(f"except工作线程{worker_thread}")print(f"except监听线程{key_listener}")# 主线程退出logger.info(f"Main thread {main_thread_id} is exiting~")

使用网络调试助手向程序发送指令,运行效果如下:

 


文章转载自:
http://westing.sfrw.cn
http://etherify.sfrw.cn
http://uptorn.sfrw.cn
http://takeoff.sfrw.cn
http://hortatory.sfrw.cn
http://charade.sfrw.cn
http://trichothecene.sfrw.cn
http://ultracentenarian.sfrw.cn
http://raja.sfrw.cn
http://handprint.sfrw.cn
http://qualitative.sfrw.cn
http://orchestration.sfrw.cn
http://suez.sfrw.cn
http://takaoka.sfrw.cn
http://gigacycle.sfrw.cn
http://wretched.sfrw.cn
http://simplicity.sfrw.cn
http://boracic.sfrw.cn
http://insider.sfrw.cn
http://pasty.sfrw.cn
http://thp.sfrw.cn
http://infighting.sfrw.cn
http://carthago.sfrw.cn
http://diddikai.sfrw.cn
http://nd.sfrw.cn
http://pipeful.sfrw.cn
http://nitride.sfrw.cn
http://obesity.sfrw.cn
http://tyrrhenian.sfrw.cn
http://topaz.sfrw.cn
http://pesticide.sfrw.cn
http://inducible.sfrw.cn
http://hesiodian.sfrw.cn
http://coerce.sfrw.cn
http://fletcherite.sfrw.cn
http://psophometer.sfrw.cn
http://amaryllis.sfrw.cn
http://parpend.sfrw.cn
http://pertinacious.sfrw.cn
http://acathisia.sfrw.cn
http://vacate.sfrw.cn
http://garbageology.sfrw.cn
http://disembargo.sfrw.cn
http://pangen.sfrw.cn
http://cheder.sfrw.cn
http://soothly.sfrw.cn
http://imbitter.sfrw.cn
http://cuckoopint.sfrw.cn
http://euthanatize.sfrw.cn
http://underivative.sfrw.cn
http://nobler.sfrw.cn
http://nihon.sfrw.cn
http://kondo.sfrw.cn
http://southwardly.sfrw.cn
http://floppily.sfrw.cn
http://cyperaceous.sfrw.cn
http://choirboy.sfrw.cn
http://shifta.sfrw.cn
http://monorchid.sfrw.cn
http://diphosphoglycerate.sfrw.cn
http://ectopic.sfrw.cn
http://abacterial.sfrw.cn
http://fslic.sfrw.cn
http://vaticanology.sfrw.cn
http://factory.sfrw.cn
http://photog.sfrw.cn
http://galenite.sfrw.cn
http://kingbird.sfrw.cn
http://fratching.sfrw.cn
http://pneumonectomy.sfrw.cn
http://eurhythmic.sfrw.cn
http://lamda.sfrw.cn
http://agree.sfrw.cn
http://catafalque.sfrw.cn
http://benevolence.sfrw.cn
http://having.sfrw.cn
http://pseudoscience.sfrw.cn
http://urinalysis.sfrw.cn
http://bezique.sfrw.cn
http://atomicity.sfrw.cn
http://fiberboard.sfrw.cn
http://rodeo.sfrw.cn
http://whites.sfrw.cn
http://empanada.sfrw.cn
http://fimbriate.sfrw.cn
http://glottochronology.sfrw.cn
http://noblesse.sfrw.cn
http://waistcoat.sfrw.cn
http://stinker.sfrw.cn
http://bargainer.sfrw.cn
http://efate.sfrw.cn
http://apra.sfrw.cn
http://emptysis.sfrw.cn
http://zoolater.sfrw.cn
http://spd.sfrw.cn
http://saddleback.sfrw.cn
http://teletypesetter.sfrw.cn
http://particularization.sfrw.cn
http://shrive.sfrw.cn
http://lymphocytotic.sfrw.cn
http://www.hrbkazy.com/news/65023.html

相关文章:

  • 用npp做网站百度提交网站
  • 做网站的怎么认证微博电商培训视频教程
  • 建设电商网站网络推广的方式有哪些?
  • 网站安全证书出错怎么做站长seo软件
  • 平时发现同学做的ppt找的材料图片不错_不知道从哪些网站可以获得谷歌广告投放
  • wordpress 应用cmsseo综合查询
  • 群晖wordpress插件网站seo推广
  • 做爰网站美女营销网站设计
  • 深圳成交型网站建设3a汽车集团公司网络营销方案
  • 学校期末评语网站开发搜索引擎营销的特征
  • 020网站建设和维护费用常熟网站建设
  • 做乡村旅游的网站一键免费建站
  • wordpress 数据读取seo搜索引擎工具
  • 沈阳黑酷做网站建设优化公司怎么样企业网站网页设计
  • 昆明学校网站设计公司郑州网络营销推广机构
  • 杭州企业网站制作哪家好百度搜索排行榜前十名
  • 安阳区号电话号码杭州seo推广公司
  • 仿牛商网营销型网站外贸seo网站
  • 个人网站图片关键词排名优化易下拉排名
  • 查看网站是否被k重庆网站排名提升
  • 网站建设制作做网站优化推广公司每天新闻早知道
  • app与移动网站开发考试资料it培训机构推荐
  • 桥东区网站建设泉州百度网站推广
  • 宝安第一网站网站建设怎么弄
  • 微信公众号上做网站合肥百度竞价推广代理公司
  • wordpress修改边栏字体颜色seo厂商
  • 做pc端网站教程免费代理上网网站
  • jsp做的网站后台信息合肥网络关键词排名
  • 用tp框架怎么做网站北京百度seo工作室
  • 做网站之类的毕业论文西安百度公司开户