Skip to content

Instantly share code, notes, and snippets.

@rrader
Created September 20, 2017 09:40
Show Gist options
  • Select an option

  • Save rrader/3d2edb0a362910b78fe640042923fc45 to your computer and use it in GitHub Desktop.

Select an option

Save rrader/3d2edb0a362910b78fe640042923fc45 to your computer and use it in GitHub Desktop.
Test open files on requests
import psutil
import requests
def open_files():
proc = psutil.Process()
return proc.open_files()
print 'on start:', open_files()
f = open('/etc/hosts', 'r')
print 'hosts file opened:', open_files()
f.close()
print 'hosts file closed:', open_files()
print
url = 'http://httpbin.org/post'
multiple_files = [
('images', ('hosts', open('/etc/hosts', 'rb'), 'plain/text')),
('images', ('resolv.conf', open('/etc/resolv.conf', 'rb'), 'plain/text'))]
r = requests.post(url, files=multiple_files)
print 'after request:', open_files()
@rrader
Copy link
Author

rrader commented Sep 20, 2017

on start: []
hosts file opened: [popenfile(path='/etc/hosts', fd=3, position=0, mode='r', flags=32768)]
hosts file closed: []

after request: [popenfile(path='/etc/hosts', fd=3, position=365, mode='r', flags=32768), popenfile(path='/etc/resolv.conf', fd=4, position=100, mode='r', flags=32768)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment