在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/ Python問答
忠妾 回答

我也剛看,試了好久,初步知道怎么回事了.
先回答你的兩個(gè)問題:
1、setDaemon所綁定的都是主線程,都是一樣的,即運(yùn)行py文件第一次創(chuàng)建的那個(gè)線程(也是主進(jìn)程),有且只有一個(gè)
2、queue.join()如果單獨(dú)使用會(huì)被無限掛起,字面翻譯為等待隊(duì)列為空,再執(zhí)行別的操作.但是他等待的隊(duì)列不是我們創(chuàng)建的aqueue,而是一個(gè)與aqueue長(zhǎng)度相等的一個(gè)"需要完成的子線程"隊(duì)列,他判斷的很可能是這個(gè)列表,當(dāng)這個(gè)列表為空時(shí)queue.join()才成立,所以如樓上的那位所說queue.join()要結(jié)合aqueue.task_done()函數(shù)來使用,aqueue.task_done()的意思是每task_done一次 就從"需要完成的子線程"隊(duì)列里刪掉一個(gè)元素,這樣在最后join的時(shí)候根據(jù)隊(duì)列長(zhǎng)度是否為零來判斷隊(duì)列是否結(jié)束,aqueue.task_done()用在子線程函數(shù)中,這樣queue.join()才知道完成了多少個(gè)子線程,才不會(huì)無限掛起,也就是為什么你沒退出的原因

但是你的程序也有問題:
主要的問題是,守護(hù)線程機(jī)制:主線程運(yùn)行完畢去結(jié)束子線程時(shí),由于有大量的子線程還在time.sleep(5),結(jié)束這些子線程會(huì)觸發(fā)異常:

Fatal Python error: could not acquire lock for <_io.BufferedWriter name='<stdout>'> at interpreter shutdown, possibly due to daemon threads

Thread 0x000019cc (most recent call first):
  File "test.py", line 13 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

這是因?yàn)?
下面的一些說法是錯(cuò)誤的,可以看我后面的補(bǔ)充,這里就不改了,是一種猜測(cè),但是應(yīng)該確實(shí)不是這樣
喂不飽的子線程:你aqueue.put(i)了是10個(gè)元素,但是卻運(yùn)行了20個(gè)子線程來"吃"這10個(gè)元素,又因?yàn)檫@20個(gè)線程都是守護(hù)進(jìn)程,當(dāng)10個(gè)吃飽了,這個(gè)10個(gè)卡在了item = aqueue.get()等待接受元素,另外的那些很有可能卡在了time.sleep(5)上,而主線程運(yùn)行完畢,準(zhǔn)備結(jié)束所有的守護(hù)進(jìn)程,我判斷,結(jié)束卡在item = aqueue.get()的守護(hù)進(jìn)程不會(huì)報(bào)錯(cuò),而結(jié)束其他程序,如time.sleep會(huì)觸發(fā)異常,這也是為啥樓上那位吧你的for i in range(20):改成了for i in range(1):的原因.

還有兩種退出的方式:
1、是在子線程里判斷隊(duì)列是否為空:

if aqueue.empty() == True:
    break

為空就退出
2、主線程通過queue向子線程發(fā)送退出命令
其實(shí)這里一般用pipe管道的,Queue隊(duì)列不好針對(duì)特定的線程進(jìn)行退出操作,大概的偽碼為:

主線程:

aqueue.put('quit')

子線程""

item = aqueue.get()
if item == 'quit':
    return
else:
    # "do something"

所以多進(jìn)程,多線程還是要控制好程序邏輯,控制好調(diào)度.

我沒用過守護(hù)進(jìn)程,我一般用的是普通的用戶進(jìn)程,這樣主線程跑完會(huì)等待所有子線程運(yùn)行完畢再結(jié)束

其實(shí)還沒完=_=:
后面的都是我的猜測(cè),算是附加的,選修:
這程序的細(xì)節(jié)也值得我們關(guān)注:
這程序如果真去實(shí)踐的話很容易炸,以下都是我的猜測(cè)
如上所述,我們修改程序,注意注釋

import queue
import threading
import time

aqueue = queue.Queue()
# 發(fā)送了0到9的十個(gè)數(shù)據(jù)
for i in range(10):
    aqueue.put(i)

def worker():
    while True:
        # 輸出當(dāng)前線程,和主線程(可以看到主線程都一樣)
        print('thread %s is running...\nmain_thread %s is running...\n\n' % (threading.current_thread().name,threading.main_thread()))
        time.sleep(1)
        item = aqueue.get()
        print(item)
        aqueue.task_done()
        print('thread end')


n = 1
"""注意這!!!!!!!!!!!!!!!!!!"""
# 運(yùn)行了10個(gè)線程來處理這十個(gè)數(shù)據(jù)
for i in range(10):
    print("run thread Counts: ",n)
    n += 1
    a = threading.Thread(target = worker)
    a.setDaemon(True)
    a.start()

aqueue.join()
print('after to do')
print('end')

10個(gè)數(shù)據(jù)10個(gè)線程,time.cleep(5)秒結(jié)果會(huì)怎么樣?運(yùn)行正常?
很不幸運(yùn)的炸了23333333
有一定的幾率報(bào)錯(cuò),和上面一樣:

Fatal Python error: could not acquire lock for <_io.BufferedWriter name='<stdout>'> at interpreter shutdown, possibly due to daemon threads

Thread 0x0000063c (most recent call first):
  File "test.py", line 13 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

我電腦上大部分運(yùn)行正常,只有幾次會(huì)這樣,為什么會(huì)這樣?
換成10個(gè)數(shù)據(jù)9個(gè)線程就不會(huì)出錯(cuò)了
我猜測(cè)的情況是,初步認(rèn)為:
直接看完整的輸出,注意看有注釋的地方:

run thread Counts:  1
thread Thread-1 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  2

thread Thread-2 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  3

thread Thread-3 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  4

thread Thread-4 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  5

thread Thread-5 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  6

thread Thread-6 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  7

thread Thread-7 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  8

thread Thread-8 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  9

thread Thread-9 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

run thread Counts:  10

thread Thread-10 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...


0
1
3
4
thread end
thread end
5
2
thread Thread-2 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

thread end
thread end
thread end
thread Thread-3 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

thread end

thread Thread-4 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

thread Thread-1 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

thread Thread-5 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...





6
8
thread Thread-6 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

thread end
thread end

thread Thread-7 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

7
9
thread Thread-9 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...
"""到這里主線程已經(jīng)完畢"""
thread end
after to do
"""
這里其實(shí)系統(tǒng)在調(diào)用守護(hù)線程的結(jié)束程序來結(jié)束所有子線程
"""
"""但是在結(jié)束守護(hù)進(jìn)程程序后,又運(yùn)行了一個(gè)不該運(yùn)行的子線程,這就是為什么會(huì)報(bào)錯(cuò)的原因"""
thread Thread-10 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

end
thread end


thread Thread-8 is running...
main_thread <_MainThread(MainThread, started 6680)> is running...

Fatal Python error: could not acquire lock for <_io.BufferedWriter name='<stdout>'> at interpreter shutdown, possibly due to daemon threads

Thread 0x00000424 (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x00000f04 (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x0000165c (most recent call first):
  File "test.py", line 13 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x000018b0 (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x00000db4 (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x00001a88 (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x0000111c (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x0000177c (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x000008e4 (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Thread 0x00001788 (most recent call first):
  File "test.py", line 14 in worker
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864 in run
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916 in _bootstrap_inner
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\threading.py", line 884 in _bootstrap

Current thread 0x00001a18 (most recent call first):

看主要的幾句

"""到這里主線程已經(jīng)完畢"""
    thread end
    after to do
    """
    這里其實(shí)系統(tǒng)在調(diào)用守護(hù)線程的結(jié)束程序來結(jié)束所有子線程
    """
    """但是在結(jié)束守護(hù)進(jìn)程程序后,又運(yùn)行了一個(gè)不該運(yùn)行的子線程,這就是為什么會(huì)報(bào)錯(cuò)的原因"""
    thread Thread-10 is running...
    main_thread <_MainThread(MainThread, started 6680)> is running...
    
    end
    thread end

先這樣吧,可以自己運(yùn)行下程序看看

看了另一個(gè)答主的,使用了a.join()也是一種選擇

改成發(fā)送10個(gè)數(shù)據(jù),用9個(gè)線程跑,效率是最高的(理論)

import queue
import threading
import time

aqueue = queue.Queue()
# 發(fā)送了0到9的十個(gè)數(shù)據(jù)
for i in range(10):
    aqueue.put(i)

def worker():
    while True:
        # 輸出當(dāng)前線程,和主線程(可以看到主線程都一樣)
        print('thread %s is running...\nmain_thread %s is running...\n\n' % (threading.current_thread().name,threading.main_thread()))
        time.sleep(5)
        item = aqueue.get()
        print(item)
        aqueue.task_done()
        print('thread end')


n = 1
"""注意這!!!!!!!!!!!!!!!!!!"""
for i in range(9):
    print("run thread Counts: ",n)
    n += 1
    a = threading.Thread(target = worker)
    a.setDaemon(True)
    a.start()

aqueue.join()
print('after to do')
print('end')

怣痛 回答

文檔里有寫啊

https://zh.nuxtjs.org/api

asyncData 可以接受一個(gè) context 參數(shù),包含了當(dāng)前環(huán)境所有信息

context.store 就能獲取到 vuex 實(shí)例了,具體內(nèi)容打開鏈接進(jìn)去看吧

尛曖昧 回答

跟你5px的scrollbar 有關(guān)。頁(yè)面比較高的時(shí)候,scrollbar會(huì)占個(gè)位置。

赱丅呿 回答

大概思路:
crontab里面添加這個(gè)xxx.py的文件,或者用supervisor管理這個(gè)進(jìn)程
然后xxx.py里面執(zhí)行subprocess.call('http-server')
不是很嚴(yán)謹(jǐn),但這個(gè)思路能實(shí)現(xiàn)

情殺 回答

bVbay8r?w=654&h=481

看了一下你的鏈接,發(fā)現(xiàn)后面就是你想附帶的參數(shù)

想確認(rèn)一下你是準(zhǔn)備用get帶params

或者還是post提交data

確認(rèn)一下

requests.get(url=url,params=data)
#
requests.post(url=url,data=data)

view.py中把網(wǎng)頁(yè)表單賦值完后info_form.save()才算保存

npm install -g vue-cli@版本號(hào)


查看版本號(hào)

vue -V

這個(gè)可以用shapes做,具體可以看看張?chǎng)涡竦倪@篇文章

另外附注:
這個(gè)也可以用已經(jīng)被廢棄的屬性region做到這個(gè)效果
詳細(xì)請(qǐng)百度,不過已經(jīng)被chrome廢棄了

別瞎鬧 回答

試一下SQLAlchemy的event吧(http://docs.sqlalchemy.org/en...
一個(gè)簡(jiǎn)單的使用例子

import sqlalchemy
from sqlalchemy import event
from models import Wallet

class User(db.Model):
  name = sqlalchemy.column(s.String)

  @staticmethod
  def after_create(mapper, connection, target):
    wallet = Wallet()
    db.session.add(wallet)
    db.session.commit()
    
event.listen(User, 'after_insert', User.after_create)
巴扎嘿 回答

crx后綴改成zip解壓。。。

乖乖噠 回答

不用格式化輸入,Python查詢數(shù)據(jù)庫(kù)有相應(yīng)的庫(kù),例如:https://pypi.python.org/pypi/...,安裝之后查詢的方法查看官方文檔:https://dev.mysql.com/doc/con...

蝶戀花 回答

v-for里面不需要寫括號(hào)的,然后就是樓上兄弟說的打印少寫了一半引號(hào)。其他貌似沒有什么問題

離殤 回答

自問自答。

module = __import__('module.%s' % modulename)
class_ = module()
func = getattr(class_, 'func')
func()
吢涼 回答

我覺得與樓主提供的的連接相比,不如分成面向?qū)ο?/code>、面向過程,以及函數(shù)式編程。這里顯然是面向?qū)ο蟮摹?/p>

選擇 回答

一個(gè) class 影響 "input-group"

孤星 回答

你看下兩個(gè)請(qǐng)求的請(qǐng)求頭是不是一樣的呢?
關(guān)注下瀏覽器中的請(qǐng)求頭,304會(huì)有:If-Modified-Since 和 If-None-Match(緩存機(jī)制)。然后Chrome調(diào)試模式中可以僅用緩存,你再刷新請(qǐng)求試試呢

瞄小懶 回答

clipboard.png

pycharm 寫python不錯(cuò),錯(cuò)誤提示也很友好