In Python 3: * various builtins and dict methods were changed to return view/iterable objects rather than lists * and the separate Python 2 view/iterable builtins and methods were removed altogether This is problematic when using these items as list (which the happens repeatedly in Odoo), but more viciously when iterating *multiple times* over them (which also happens, which I've messed up multiple times while writing this, and which is a pain to debug even when you've just created the issue). Convert all code using these to semantics-matching cross-version helper functions to get the LCD behaviour between P2 and P3, and forbid the builtins via lint. issue #8530
45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import time
|
|
import sys
|
|
|
|
from odoo import models, api
|
|
|
|
class m(models.Model):
|
|
""" This model exposes a few methods that will consume between 'almost no
|
|
resource' and 'a lot of resource'.
|
|
"""
|
|
_name = 'test.limits.model'
|
|
|
|
@api.model
|
|
def consume_nothing(self):
|
|
return True
|
|
|
|
@api.model
|
|
def consume_memory(self, size):
|
|
l = [0] * size
|
|
return True
|
|
|
|
@api.model
|
|
def leak_memory(self, size):
|
|
if not hasattr(self, 'l'):
|
|
type(self).l = []
|
|
self.l.append([0] * size)
|
|
return True
|
|
|
|
@api.model
|
|
def consume_time(self, seconds):
|
|
time.sleep(seconds)
|
|
return True
|
|
|
|
@api.model
|
|
def consume_cpu_time(self, seconds):
|
|
t0 = time.clock()
|
|
t1 = time.clock()
|
|
while t1 - t0 < seconds:
|
|
for i in range(10000000):
|
|
x = i * i
|
|
t1 = time.clock()
|
|
return True
|