pogodevorg / pgoapi

Unofficial PokemonGO API in Python
https://pogodev.org
Other
852 stars 475 forks source link

get_map_objects - Memory issues #53

Closed tienthanhdhcn closed 8 years ago

tienthanhdhcn commented 8 years ago

Hi guys, when I run to get_map_object. The memory is fulfilled quickly and I get the error out of memory. What should I do?

ProLoDs commented 8 years ago

can confirm, looks like the shared lib is loaded new each call and not unloaded or reused. something like this should work.. http://stackoverflow.com/questions/359498/how-can-i-unload-a-dll-using-ctypes-in-python

Wouter93 commented 8 years ago

Possibly related to https://github.com/keyphact/pgoapi/issues/33

tienthanhdhcn commented 8 years ago

@Wouter93 please let me know what did you to do fix the problem. I did move session to outside the loop but still get the same problem :(

Wouter93 commented 8 years ago

I'll just paste my changes because I have no experience with git/github

in rpc_api: I commented out the session inits

    def __init__(self, auth_provider):

        self.log = logging.getLogger(__name__)

    #COMMENTED THESE OUT
        #self._session = requests.session()
        #self._session.headers.update({'User-Agent': 'Niantic App'})
        #self._session.verify = False

        self._auth_provider = auth_provider

        """ mystic unknown6 - revolved by PokemonGoDev """
        self._signature_gen = False
        self._signature_lib = None

        if RpcApi.START_TIME == 0:
            RpcApi.START_TIME = get_time(ms = True)

        if RpcApi.RPC_ID == 0:
            RpcApi.RPC_ID = int(random.random() * 10 ** 18)

In pgoapi: I added 1 line under the call() in PGoApiRequest

class PGoApiRequest:
    def call(self):
        ...

        request = RpcApi(self._auth_provider)
        request._session = self.__parent__._session   # <----- NEW LINE

        lib_path = self.__parent__.get_signature_lib()

        ....

Also in pgoapi: added session init in pgoapi constructor:

    def __init__(self, provider = None, oauth2_refresh_token = None, username = None, password = None, position_lat = None, position_lng = None, position_alt = None):
        ....

        self._position_lat = position_lat
        self._position_lng = position_lng
        self._position_alt = position_alt

        self._signature_lib = None

        self._session = requests.session()   # <--- NEW LINE
        self._session.headers.update({'User-Agent': 'Niantic App'})   # <--- NEW LINE
        self._session.verify = False   # <--- NEW LINE
elliottcarlson commented 8 years ago

This is related to https://github.com/tejado/pgoapi/issues/90 - a Pull Request would be useful.