Closed
Description
I'm running the following code in google colab to download a large file (approximately 2.5 GB).
import io
from google.colab import auth
from googleapiclient.discovery import build
from googleapiclient.http import MediaIoBaseDownload
auth.authenticate_user()
drive_service = build('drive', 'v3')
file_id = '1M5ZTq0Iu0kttOZb1FpDPRG-TsagdYbIQ'
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print('Percent downloaded', int(100 * status.progress()))
downloaded.seek(0)
f = open('data.tar.gz', 'wb')
f.write(downloaded.read())
f.close()
del drive_service, downloader, downloaded, f
printm()
I am using the following script to determine memory usage:
!ln -sf /opt/bin/nvidia-smi /usr/bin/nvidia-smi
!pip install gputil
!pip install psutil
!pip install humanize
import psutil
import humanize
import os
def printm():
process = psutil.Process(os.getpid())
print("Gen RAM Free: " + humanize.naturalsize( psutil.virtual_memory().available ), " I Proc size: " + humanize.naturalsize( process.memory_info().rss))
printm()
However, it appears that there is a memory leak in the api client. I print the amount of memory usage at the very beginning, before running anything:
Requirement already satisfied: gputil in /usr/local/lib/python3.6/dist-packages (1.3.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from gputil) (1.14.3)
Requirement already satisfied: psutil in /usr/local/lib/python3.6/dist-packages (5.4.5)
Requirement already satisfied: humanize in /usr/local/lib/python3.6/dist-packages (0.5.1)
Gen RAM Free: 13.0 GB I Proc size: 146.8 MB
After running the download script, which as you can see deletes all of the variables, as well as the %reset
magic, the amount of memory is still much less than before:
Requirement already satisfied: gputil in /usr/local/lib/python3.6/dist-packages (1.3.0)
Requirement already satisfied: numpy in /usr/local/lib/python3.6/dist-packages (from gputil) (1.14.3)
Requirement already satisfied: psutil in /usr/local/lib/python3.6/dist-packages (5.4.5)
Requirement already satisfied: humanize in /usr/local/lib/python3.6/dist-packages (0.5.1)
Gen RAM Free: 6.7 GB I Proc size: 6.5 GB