models.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import time
  4. import sys
  5. from odoo import models, api
  6. class m(models.Model):
  7. """ This model exposes a few methods that will consume between 'almost no
  8. resource' and 'a lot of resource'.
  9. """
  10. _name = 'test.limits.model'
  11. _description = 'Test Limits Model'
  12. @api.model
  13. def consume_nothing(self):
  14. return True
  15. @api.model
  16. def consume_memory(self, size):
  17. l = [0] * size
  18. return True
  19. @api.model
  20. def leak_memory(self, size):
  21. if not hasattr(self, 'l'):
  22. type(self).l = []
  23. self.l.append([0] * size)
  24. return True
  25. @api.model
  26. def consume_time(self, seconds):
  27. time.sleep(seconds)
  28. return True
  29. @api.model
  30. def consume_cpu_time(self, seconds):
  31. t0 = time.process_time()
  32. t1 = time.process_time()
  33. while t1 - t0 < seconds:
  34. for i in range(10000000):
  35. x = i * i
  36. t1 = time.process_time()
  37. return True