HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
SystemCommandHandler.py
Go to the documentation of this file.
1 """
2 HCE project, Python bindings, Distributed Tasks Manager application.
3 SystemCommandHandler Class content main functional support different system command.
4 
5 @package: app
6 @file SystemCommandHandler.py
7 @author Alexander Vybornyh <alexander.hce.cluster@gmail.com>
8 @link: http://hierarchical-cluster-engine.com/
9 @copyright: Copyright &copy; 2013-2016 IOIX Ukraine
10 @license: http://hierarchical-cluster-engine.com/license/
11 @since: 0.1
12 """
13 
14 import resource
15 import gc
16 
17 
18 
20 class SystemCommandHandler(object):
21 
22  ERROR_NOT_SUPPORTED_TYPE = 'Not supported type of SystemCommandHandler'
23 
24  ERROR_OK = 0
25  ERROR_FAIL = 1
26 
29  def __init__(self, logger=None):
30  self.logger = logger
31  self.errorMsg = ''
33 
34 
35 
40  def execute(self, typeNumber, inputData=None):
41  #variable for result
42  ret = self.ERROR_FAIL
43  if self.logger is not None:
44  self.logger.debug('type: ' + str(typeNumber))
45 
46  try:
47  if int(typeNumber) >= len(self.handlers) or int(typeNumber) < 0:
48  raise Exception(self.ERROR_NOT_SUPPORTED_TYPE + ' (' + str(typeNumber) + ')')
49 
50  (self.handlers[int(typeNumber)])(inputData)
51  ret = self.ERROR_OK
52  except Exception, err:
53  self.errorMsg = str(err)
54 
55  return ret
56 
57 
58 
61  def onGarbageCollectorCleanupHandler(self, inputData=None): # pylint: disable=W0613
62  gc.collect()
63  if self.logger is not None:
64  self.logger.debug('Memory usage: %s (kb)' % resource.getrusage(resource.RUSAGE_SELF).ru_maxrss)
65  self.logger.debug('GC generations count: ' + str(gc.get_count()))
string ERROR_NOT_SUPPORTED_TYPE
Constans of error messages.
def execute(self, typeNumber, inputData=None)
Execute system command.
Class SystemCommandHandler for support different system command.
def __init__(self, logger=None)
Constructor.
def onGarbageCollectorCleanupHandler(self, inputData=None)
Handler of garbage collector cleanup.