這篇文章主要講解了flask怎么開啟多線程,內(nèi)容清晰明了,對(duì)此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會(huì)有幫助。

在我之前解釋了flask如何支持多線程主要通過兩個(gè)類來實(shí)現(xiàn),LocalStack和Local,在Local中有兩個(gè)屬性,__storage__和__ident_func__,后者用來獲取線程id,從而區(qū)分不同線程發(fā)來的請(qǐng)求
這次要說的是flask如何開啟多線程
先從app.run()這個(gè)方法看起
def run(self, host=None, port=None, debug=None, **options):
from werkzeug.serving import run_simple
if host is None:
host = '127.0.0.1'
if port is None:
server_name = self.config['SERVER_NAME']
if server_name and ':' in server_name:
port = int(server_name.rsplit(':', 1)[1])
else:
port = 5000
if debug is not None:
self.debug = bool(debug)
options.setdefault('use_reloader', self.debug)
options.setdefault('use_debugger', self.debug)
try:
run_simple(host, port, self, **options) #會(huì)進(jìn)入這個(gè)函數(shù)
finally:
# reset the first request information if the development server
# reset normally. This makes it possible to restart the server
# without reloader and that stuff from an interactive shell.
self._got_first_request = False
網(wǎng)站名稱:flask怎么開啟多線程-創(chuàng)新互聯(lián)
URL地址:http://chinadenli.net/article6/dsjjig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、虛擬主機(jī)、網(wǎng)站營(yíng)銷、網(wǎng)站內(nèi)鏈、網(wǎng)站導(dǎo)航、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容