#生產者消費者模型(單執行緒高併發)
1、低效率模式 產完在統一給
importtime
defproducter():
ret =
for i in range(10):
time.sleep(0.1)
return
retdef
consumer(res):
for index,baozi in
enumerate(res):
time.sleep(0.1)
print('
第%s個人,吃了%s
' %(index,baozi))
res =producter()
print(consumer(res))
2、高效率模式 產乙個給乙個
importtime
defconsumer(name):
print('
我是[%s],我在排隊買包子
' %name)
while
true:
baozi = yield
time.sleep(1) #
模擬在achun在吃包子
print('
%s很開心,%s很好吃
' %(name,baozi))
defproducter():
population1 = consumer('
achun
') #
生成器函式
population1.__next__
() population2 = consumer('
alin
') #
生成器函式
population2.__next__
()
for i in range(10):
time.sleep(1) #
模擬在在做包子
population1.send('
鮮肉菜包 %s
' %i)
population2.send(
'鮮肉菜包 %s
' %i)
producter()
PHP應用函式實現小功能
1.php 處理數字為金錢格式 10,000,000 number format 需要轉換的數字,保留小數個數,小數點符號,每三位的分隔符 echo number format 1000000 預設顯示 1,000,000 echo number format 1000000 2 預設顯示 1,00...
iOS常用小功能
這些功能比較實用,而且實現的 也比較簡單 此方式打完 不會返回應用介面,而是停留在打 介面 nsurl url nsurl urlwithstring tel 10086 此方法撥號之前會提示是否撥號,打完 後會回到應用介面,但是因為是私有api,蘋果不建議使用 nsurl url nsurl ur...
JS實用小功能
獲取使用者ip ua 城市 操作cookie function getcookie c name return unescape document.cookie.substring c start,c end return function setcookie c name,value,expire...