程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The fifth notes of 2022 Python winter vacation advanced training

編輯:Python
 One 、 Timer Use a timer to trigger some events
Example :
import threading
import time
def run():
print(' Timer on ')
timer = threading.Timer(5,run) # Re enable the timer , Realize the cycle
timer.start()
if __name__ == '__main__':
t1 = threading.Timer(1,function=run) # Create a timer
#5 Start thread in seconds # Method
t1.start()

Two 、 queue

'''
queue.Queue() First in, first out
queue.LifoQueue() After the first out
queue.PriorityQueue() Priority can be set
Transmissible parameters maxsize Set the amount of data that can be stored
queue.LifoQueue() After the first out
queue.PriorityQueue() Priority can be set
Transmissible parameters maxsize Set the amount of data that can be stored
Queue.qsize() The amount of data obtained
Queue.full() Determine if the queue is full
Queue.empty() Determine whether the queue is empty
Queue.join() Wait for the thread to complete
'''
import queue
q = queue.Queue(maxsize=3) # Create a queue The maximum capacity is 3
q.put(1)# Put in numbers 1
q.put(2)
q.put(3)
# q.put(4) # Put in an individual that exceeds the maximum capacity , The program will wait for the individual inside to take out
# q.put(4,False,timeout=3)# After setting the waiting time , Will wait for 3 Seconds later , Application error
print(q.queue) # Print out the individuals in the queue : deque([1, 2, 3])
print(q.qsize()) # Print the number of individuals in the queue : 3
q.get() # Take out one individual in the queue in turn
print(q.full()) # Judge whether the queue is full Print as False or Ture
print(q.empty()) # Judge whether the queue is full Print as False or Ture
print(q.get()) # Print the individuals taken out this time
# q1 = queue.PriorityQueue() Priority can be set
# q1.put(2,'nihao1')
# q1.put(5,'nihao2')
# ( priority , Put elements )
producer 、 Classic consumer cases 
''' Producer consumer model '''
import queue
import threading
import time
q = queue.Queue(maxsize=10) # Create a queue
def put_in():
count = 1
while True:
q.put(f' Brown sugar Ciba {count}') # Put in
print(f' Brown sugar Ciba {count} Out of the pot ')
count += 1
time.sleep(1) # Sleep for a second
def get_out(name):
while True: # Cycle all the time
print(f'{name} Ate {q.get()}')
time.sleep(1)
if __name__ == '__main__':
p = threading.Thread(target=put_in) # Create thread , Call function
p.start()
g = threading.Thread(target=get_out,args=('qq',)) # Create thread , Call function
# The incoming object should be in the form of tuple (a,b)
g.start()
 Thread pool :http://c.biancheng.net/view/2627.html

MySQL Workbench Use the graphic tutorial - Simple books (jianshu.com)

【 Artificial intelligence -Python Connect MySQL】Mysql、pymysql Database foundation +python Detailed explanation of operation database !( Attached courseware source code information !)_ Bili, Bili _bilibili

Python3 MySQL Database connection – PyMySQL drive | Novice tutorial (runoob.com)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved