最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python出現(xiàn)RuntimeError錯(cuò)誤問題及解決

 更新時(shí)間:2022年05月23日 10:29:41   作者:舔狗一無所有  
這篇文章主要介紹了python出現(xiàn)RuntimeError錯(cuò)誤問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

下面是出現(xiàn)的錯(cuò)誤解釋

RuntimeError: 
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.
 
        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:
 
            if __name__ == '__main__':
                freeze_support()
                ...
 
        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

下面是出現(xiàn)錯(cuò)誤代碼的原代碼

import multiprocessing as mp
import time
from urllib.request import urlopen,urljoin
from bs4 import BeautifulSoup
import re
 
base_url = "https://morvanzhou.github.io/"
 
#crawl爬取網(wǎng)頁
def crawl(url):
    response = urlopen(url)
    time.sleep(0.1)
    return response.read().decode()
 
#parse解析網(wǎng)頁
def parse(html):
    soup = BeautifulSoup(html,'html.parser')
    urls = soup.find_all('a',{"href":re.compile('^/.+?/$')})
    title = soup.find('h1').get_text().strip()
    page_urls = set([urljoin(base_url,url['href'])for url in urls])
    url = soup.find('meta',{'property':"og:url"})['content']
    return title,page_urls,url
 
unseen = set([base_url])
seen = set()
restricted_crawl = True
 
pool = mp.Pool(4)
count, t1 = 1, time.time()
while len(unseen) != 0:                 # still get some url to visit
    if restricted_crawl and len(seen) > 20:
            break
    print('\nDistributed Crawling...')
    crawl_jobs = [pool.apply_async(crawl, args=(url,)) for url in unseen]
    htmls = [j.get() for j in crawl_jobs]      # request connection
 
    print('\nDistributed Parsing...')
    parse_jobs = [pool.apply_async(parse, args=(html,)) for html in htmls]
    results = [j.get() for j in parse_jobs]    # parse html
 
    print('\nAnalysing...')
    seen.update(unseen)         # seen the crawled
    unseen.clear()              # nothing unseen
 
    for title, page_urls, url in results:
        print(count, title, url)
        count += 1
        unseen.update(page_urls - seen)     # get new url to crawl
print('Total time: %.1f s' % (time.time()-t1))    # 16 s !!!

這是修改后的正確代碼

import multiprocessing as mp
import time
from urllib.request import urlopen,urljoin
from bs4 import BeautifulSoup
import re
?
base_url = "https://morvanzhou.github.io/"
?
#crawl爬取網(wǎng)頁
def crawl(url):
? ? response = urlopen(url)
? ? time.sleep(0.1)
? ? return response.read().decode()
?
#parse解析網(wǎng)頁
def parse(html):
? ? soup = BeautifulSoup(html,'html.parser')
? ? urls = soup.find_all('a',{"href":re.compile('^/.+?/$')})
? ? title = soup.find('h1').get_text().strip()
? ? page_urls = set([urljoin(base_url,url['href'])for url in urls])
? ? url = soup.find('meta',{'property':"og:url"})['content']
? ? return title,page_urls,url
?
def main():
? ? unseen = set([base_url])
? ? seen = set()
? ? restricted_crawl = True
?
? ? pool = mp.Pool(4)
? ? count, t1 = 1, time.time()
? ? while len(unseen) != 0: ? ? ? ? ? ? ? ? # still get some url to visit
? ? ? ? if restricted_crawl and len(seen) > 20:
? ? ? ? ? ? ? ? break
? ? ? ? print('\nDistributed Crawling...')
? ? ? ? crawl_jobs = [pool.apply_async(crawl, args=(url,)) for url in unseen]
? ? ? ? htmls = [j.get() for j in crawl_jobs] ? ? ?# request connection
?
? ? ? ? print('\nDistributed Parsing...')
? ? ? ? parse_jobs = [pool.apply_async(parse, args=(html,)) for html in htmls]
? ? ? ? results = [j.get() for j in parse_jobs] ? ?# parse html
?
? ? ? ? print('\nAnalysing...')
? ? ? ? seen.update(unseen) ? ? ? ? # seen the crawled
? ? ? ? unseen.clear() ? ? ? ? ? ? ?# nothing unseen
?
? ? ? ? for title, page_urls, url in results:
? ? ? ? ? ? print(count, title, url)
? ? ? ? ? ? count += 1
? ? ? ? ? ? unseen.update(page_urls - seen) ? ? # get new url to crawl
? ? print('Total time: %.1f s' % (time.time()-t1)) ? ?# 16 s !!!
?
?
if __name__ == '__main__':
? ? main()

綜上可知,就是把你的運(yùn)行代碼整合成一個(gè)函數(shù),然后加入

if __name__ == '__main__':
? ? main()

這行代碼即可解決這個(gè)問題。

python報(bào)錯(cuò):RuntimeError

python報(bào)錯(cuò):RuntimeError:fails to pass a sanity check due to a bug in the windows runtime這種類型的錯(cuò)誤

這種錯(cuò)誤原因

1.當(dāng)前的python與numpy版本之間有什么問題,比如我自己用的python3.9與numpy1.19.4會導(dǎo)致這種報(bào)錯(cuò)。

2.numpy1.19.4與當(dāng)前很多python版本都有問題。

解決辦法

在File->Settings->Project:pycharmProjects->Project Interpreter下將numpy版本降下來就好了。

1.打開interpreter,如下圖:

第一步

2.雙擊numpy修改其版本:

在這里插入圖片描述

3.勾選才能修改版本,將需要的低版本導(dǎo)入即可:

第三步

弄完了之后,重新運(yùn)行就好。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 提升python處理速度原理及方法實(shí)例

    提升python處理速度原理及方法實(shí)例

    這篇文章主要介紹了提升python處理速度原理及方法實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-12-12
  • 基于python實(shí)現(xiàn)模擬數(shù)據(jù)結(jié)構(gòu)模型

    基于python實(shí)現(xiàn)模擬數(shù)據(jù)結(jié)構(gòu)模型

    這篇文章主要介紹了基于python實(shí)現(xiàn)模擬數(shù)據(jù)結(jié)構(gòu)模型,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • Pyhton中單行和多行注釋的使用方法及規(guī)范

    Pyhton中單行和多行注釋的使用方法及規(guī)范

    大家都知道python中的注釋有多種,有單行注釋,多行注釋,批量注釋,中文注釋也是常用的。python注釋也有自己的規(guī)范,這篇文章文章中會給大家詳細(xì)介紹Pyhton中單行和多行注釋的使用方法及規(guī)范,有需要朋友們可以參考借鑒。
    2016-10-10
  • Python實(shí)現(xiàn)線性擬合及繪圖的示例代碼

    Python實(shí)現(xiàn)線性擬合及繪圖的示例代碼

    在數(shù)據(jù)處理和繪圖中,我們通常會遇到直線或曲線的擬合問題,本文主要介紹了Python實(shí)現(xiàn)線性擬合及繪圖的示例代碼,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-04-04
  • Python把csv文件轉(zhuǎn)換為excel文件

    Python把csv文件轉(zhuǎn)換為excel文件

    本文主要介紹了Python把csv文件轉(zhuǎn)換為excel文件,可以使用xlrd,xlrwt,openpyxl,xlwings,pandas 等庫操作 Excel,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-04-04
  • python 基于PYMYSQL使用MYSQL數(shù)據(jù)庫

    python 基于PYMYSQL使用MYSQL數(shù)據(jù)庫

    這篇文章主要介紹了python 基于PYMYSQL使用MYSQL數(shù)據(jù)庫的方法,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2020-12-12
  • 詳解Python利用APScheduler框架實(shí)現(xiàn)定時(shí)任務(wù)

    詳解Python利用APScheduler框架實(shí)現(xiàn)定時(shí)任務(wù)

    在做一些python工具的時(shí)候,常常會碰到定時(shí)器問題,總覺著使用threading.timer或者schedule模塊非常不優(yōu)雅。所以本文將利用APScheduler框架實(shí)現(xiàn)定時(shí)任務(wù),需要的可以參考一下
    2022-03-03
  • 快速進(jìn)修Python指南之控制if-else循環(huán)技巧

    快速進(jìn)修Python指南之控制if-else循環(huán)技巧

    這篇文章主要為大家介紹了Java開發(fā)者的Python快速進(jìn)修指南之控制之if-else和循環(huán)技巧示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12
  • Python json 錯(cuò)誤xx is not JSON serializable解決辦法

    Python json 錯(cuò)誤xx is not JSON serializable解決辦法

    這篇文章主要介紹了Python json 錯(cuò)誤xx is not JSON serializable解決辦法的相關(guān)資料,需要的朋友可以參考下
    2017-03-03
  • NumPy 數(shù)組屬性的具體使用

    NumPy 數(shù)組屬性的具體使用

    本文主要介紹了NumPy 數(shù)組屬性的具體使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08

最新評論

巨鹿县| 万宁市| 大洼县| 色达县| 安庆市| 百色市| 安新县| 成武县| 习水县| 墨江| 邹平县| 贞丰县| 龙口市| 仙居县| 泰安市| 宕昌县| 湘阴县| 海丰县| 长寿区| 东方市| 莱西市| 永嘉县| 辉县市| 葫芦岛市| 广宗县| 卓资县| 革吉县| 东兴市| 象州县| 万安县| 兴隆县| 三台县| 安泽县| 阳朔县| 邵武市| 武威市| 信阳市| 怀来县| 林州市| 大方县| 日土县|