簡體   English   中英

通過 python 3.7 了解異常內存使用情況

[英]Understanding anomalous memory usage by python 3.7

我在 macbook pro 上使用 OSX 10.13.6 並從 home brew 運行 Python 3.7.6。 當我從命令行運行python ,它需要幾分鍾才能啟動。 最終啟動后,我查看任務管理器,它使用了約 11GB 的壓縮內存。 我沒有運行任何程序或加載任何庫,我只是在啟動 python 解釋器。

當我在 CentOS 7 機器上運行 python 3.7 時,它使用的是 8MB。

世界正在發生什么? 為什么python在我的mac上使用這么多內存? 它並不總是這樣,如果我沒有記錯的話,我想我最近(在過去 6 個月內)不得不從自制軟件重新安裝 python。

我使用~/.pystartup保存我的python歷史記錄。 我有

historyPath = "/Users/user/.pyhistory"
def save_history(historyPath=historyPath):
    import readline
    readline.write_history_file(historyPath)

if os.path.exists(historyPath):
    print("Reading python history ... {}".format)
    readline.read_history_file(historyPath)

atexit.register(save_history)
del os, atexit, readline, rlcompleter, save_history, historyPath

在某些時候,我一定不小心在python解釋器中粘貼了一個大文件。 我的~/.pyhistory文件大小為 1.6GB,有 146322287 行。 刪除它,解決了我的問題, python又回到在我的 mac 上使用 MB 了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM