2015-04-03 121 views
-1

我有一個max recursion depth錯誤我發瘋瓶最大遞歸深度

在燒瓶__init__.py文件我有:

def getVPCs(): 
    """ 
    This is the function that loops through the accounts and regions and does all the connections. 
    """ 

答:

@app.route('/vpcs') 
@app.route('/vpcs/<vpc>') 
def getVPCs(vpc=False): 
    """ 
    Get the vpcs. 
    """ 
    results = getVPCs() 
    return jsonify(**results) 

它從調用函數功能,通過配置文件與帳戶密鑰

accounts = getAccountCreds() 

    vpc_list = [] 
    try: 

循環每一個區域... #爲每個區域 對R在國家和地區:

循環每一個賬戶的

 # for each of the 8,yes 8, AWS accounts... 
     for account,keys in accounts.iteritems(): 
     conn = VPCConnection(region=ec2.get_region(r),aws_access_key_id=keys[0],aws_secret_access_key=keys[1]) 

獲取所有的VPC每個帳戶...

  vpcs = conn.get_all_vpcs() 
      if formatVPC(account,vpcs[0]): 
       vpc_list.append(formatVPC(account,vpcs[0])) 
      return vpc_list 
    except boto.exception.BotoServerError, e: 
    print e 

其中還呼籲:

def formatVPC(account,instance): 
    """ 
    Function to format VPC data. 
    Keys we want: 
    - id 
    - instance_tenancy 
    - tags 
    - region.name 
    - region.connection 
    - region.endpoint 
    - state 
    - cidr_block 
    """ 
    result_dict = {} 
    if instance: 
     result_dict['account'] = account 
     result_dict['id'] = instance.id 
     result_dict['cidr_block'] = instance.cidr_block 
     result_dict['instance_tenancy'] = instance.instance_tenancy 
     result_dict['region'] = {'name':instance.region.name,'connection': instance.region.connection,'endpoint':instance.region.endpoint} 

     if result_dict: 
      return result_dict 

錯誤:

Traceback (most recent call last): 
    File "/Library/Python/2.7/site-packages/flask/app.py", line 1836, in __call__ 
return self.wsgi_app(environ, start_response) 
File "/Library/Python/2.7/site-packages/flask/app.py", line 1820, in wsgi_app 
response = self.make_response(self.handle_exception(e)) 
File "/Library/Python/2.7/site-packages/flask/app.py", line 1403, in handle_exception 
reraise(exc_type, exc_value, tb) 
File "/Library/Python/2.7/site-packages/flask/app.py", line 1817, in wsgi_app 
response = self.full_dispatch_request() 
File "/Library/Python/2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request 
rv = self.handle_user_exception(e) 
File "/Library/Python/2.7/site-packages/flask/app.py", line 1381, in handle_user_exception 
reraise(exc_type, exc_value, tb) 
File "/Library/Python/2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request 
rv = self.dispatch_request() 
File "/Library/Python/2.7/site-packages/flask/app.py", line 1461, in dispatch_request 
return self.view_functions[rule.endpoint](**req.view_args) 
+0

'getVPCs()'自稱永遠。 – 2015-04-03 02:40:37

回答

3

It calls the functions from:

不,從您的代碼段getVPCs只是自稱:

@app.route('/vpcs') 
@app.route('/vpcs/<vpc>') 
def getVPCs(vpc=False): 
    """ 
    Get the vpcs. 
    """ 
    results = getVPCs() # Here. 
    return jsonify(**results) 

和這樣做遞歸,沒有任何的 「邊界」 比recursion limit等,導致RuntimeErrormaximum recursion depth exceeded你所提到的。

更改這些功能的名稱之一(當然,如果需要,調整通話)。

+0

Oy! ....我真是個白癡。非常尷尬。 – 2015-04-03 03:01:26

-1

https://docs.python.org/2/library/sys.html

sys.getrecursionlimit() 返回的遞歸限制的當前值,Python解釋堆棧的最大深度。此限制可防止無限遞歸導致C堆棧溢出並導致Python崩潰。它可以通過setrecursionlimit()來設置。

+0

這實際上並沒有解決問題,它只是推遲它。 – davidism 2015-04-03 02:35:30