Giter Site home page Giter Site logo

vdisk's People

Contributors

cookpan001 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vdisk's Issues

下载大文件时内存会吃光

def get(self, host, api, queries={}):
    try:
        if isinstance(api, unicode):
            api = api.encode('utf-8')
        else:
            api = str(api)
        url = host.strip('/') + '/' + urllib.quote(api.strip('/'))
        queries = self.encode_queries(queries)
        request = urllib2.Request('%s?%s' % (url, queries))
        # set timeout.
        if self.python_version_is_bigger_than_2_4:
            response = urllib2.urlopen(request, timeout=self.timeout)
        else:
            # http://stackoverflow.com/questions/2084782/timeout-for-urllib2-urlopen-in-pre-python-2-6-versions
            import socket
            socket.setdefaulttimeout(self.timeout)
            response = urllib2.urlopen(request)
        return response.read()
    except urllib2.HTTPError,e:
        return e.read()
    except urllib2.URLError,e:
        return e.read()

这里 return response.read() 当文件很大时,会把内存吃光的

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.