修改 roc 连接 can demon 时间 案例分析 连接池
- # 属性进行封装 以方便对数据传入值合法性进行判断
- @daemon.setter # 将self._daemonic
- def daemon(self, daemonic):
- if not self._initialized:
- raise RuntimeError("Thread.__init__() not called")
- if self._started.is_set():
- raise RuntimeError("cannot set daemon status of active thread")
- self._daemonic = daemonic
- # 判断此线程是否是守护线程
- def isDaemon(self):
- return self.daemon
- #通过方法修改daemonic属性值 不建议使用
- def setDaemon(self, daemonic):
- self.daemon = daemonic
- # encoding:utf-8
- # Author:"richie"
- # Date:8/29/2017
- # python线程:线程的调度-守护线程
- from threading import Thread,Timer
- import time
- class MyCommon(Thread):
- def run(self):
- for i in range(1,5):
- t = Timer(7, self.print_msg, args=(i,))
- t.start()
- def print_msg(self,i):
- print("线程1第" + str(i) + "次执行!")
- class MyDaemon(Thread):
- """
- 守护线程不可以在重新new thread
- """
- def run(self):
- for i in range(9999999):
- print("后台线程第" + str(i) + "次执行!")
- time.sleep(2)
- if __name__ == ‘__main__‘:
- t1 = MyCommon()
- t2 = MyDaemon()
- t2.deamon = True # 设置为守护线程
- t1.start()
- t2.start()
- D:\Python\Python3.6\python.exe D:/Python/PythonProgram/day35/案例分析.py
- 后台线程第0次执行!
- 后台线程第1次执行!
- 后台线程第2次执行!
- 后台线程第3次执行!
- 线程1第1次执行!
- 线程1第2次执行!
- 线程1第3次执行!
- 线程1第4次执行!
- Process finished with exit code 0
Python线程:线程的调度-守护线程
来源: http://www.bubuko.com/infodetail-2282043.html