File: models.py

package info (click to toggle)
oca-core 11.0.20180730-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 509,684 kB
  • sloc: xml: 258,806; python: 164,081; sql: 217; sh: 92; makefile: 16
file content (44 lines) | stat: -rw-r--r-- 1,025 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- 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