资源简介
Python的多线程示例程序。zip压缩包里只有一个run.py文件,演示怎么在python里使用多线程。

代码片段和文件信息
#_*_ coding:utf-8 _*_
import requests
import json
import time
import re
import thread
import threading
haveRun = False
printlock = threading.Lock()
def mprint(mstr):
printlock.acquire()
print(mstr.encode(‘gb2312‘))
printlock.release()
def ThreadFun(datauserpassword):
mprint(user+‘--进入线程:‘+data+‘;‘+password)
while(True):
time.sleep(5)
try:
succon = AddGRRZ(data user password)
# mprint(con)
if suc:
mprint(user+‘退出线程:添加成功‘)
break
else:
mprint(user+‘添加失败,重试‘)
continue
except:
mprint(user+‘日志服务器异常,重试‘)
continue
hatime = False
def schedule():
while(True):
try:
timenow = time.strftime(‘%H:%M‘ time.localtime(time.time()))
if timenow.find(‘21:55‘) > -1:
if not haveRun:
data = time.strftime(‘%Y-%m-%d‘ time.localtime(time.time()))
mprint(‘‘+data)
thread.start_new_thread(ThreadFun (data‘user‘‘123456‘))
thread.start_new_thread(ThreadFun (data ‘user2‘ ‘123456‘))
thread.start_new_thread(ThreadFun (data ‘user3‘ ‘4‘))
thread.start_new_thread(ThreadFun (data ‘user4‘ ‘sss‘))
haveRun = True
else:
haveRun=False
if timenow.find(‘:44‘)>-1:
if not hatime:
mprint(timenow+‘--running...‘)
hatime=True
else:
hatime=False
except Exception as e:
continue
time.sleep(1)
def main():
mprint(‘开始运行‘)
schedule()
def AddGRRZ(datauserNamepassWord):
#define url
mprint(userName+‘;AddGRRZ();‘+data+‘;pw:‘+passWord)
if __name__ == “__main__“:
import sys
reload(sys)
sys.setdefaultencoding(‘utf8‘)
main()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2109 2019-02-26 22:03 run.py
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 一个多线程智能爬虫,爬取网站小说
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
评论
共有 条评论