Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

gisce/spawn_oop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ This module is replaced with the combination of OORQ and Autoworker ⚠️

Spawn Open Object Processes

Spawns OpenERP instances for functions that consumes a lot of cpu. You can lock calls to one instance only by uniq param.

Requirements

Tested on OpenERP 5.0.X

  • psutil
  • Erppeek

Example

from spawn_oop import spawn


class ResPartner(osv.osv):
    """Inherit class from res.partner.
    """
    _inherit = 'res.partner'

    @spawn()
    def consumes_lot_of_cpu(self, cursor, uid, ids, context=None):
        """Some hard function.
        """
        y = 0
        for x in range(0, 10000000000):
            y += x
        return y

ResPartner()

When ResPartner.consumes_lot_of_cpu() is called, another OpenERP instance is started, then via xmlrpc we call consumes_lot_of_cpu() in that new instance, so the main openerp process doesn't get overloaded.

Example for uniq

from spawn_oop import spawn


class ResPartner(osv.osv)
    """Inherit class from res.partner
    """
    _inherit = 'res.partner'

    @spawn(uniq=True)
    def consumes_lot_of_cpu(self, cursor, uid, ids, context=None):
        """Some hard function.
        """
        y = 0
        for x in range(0, 10000000000):
            y += x
        return y

ResPartner()

Now consumes_lot_of_cpu() is locked when is running.