class_docstr: CPU and Memory logger.
  
  Class for starting a monitor job of CPU and memory utilization in the
  background in a Python script. The ``monitor`` class records the
  ``cpu_percent``, ``rss`` and ``vms`` as collected by the
  psutil_ library for the parent process' pid.
  
  CPU usage and memory utilization are stored as attributes in numpy arrays.
  
  .. _psutil: https://pypi.python.org/pypi/psutil
  
  Examples
  --------
  >>> from time import sleep
  >>> from mlens.utils.utils import CMLog
  >>> cm = CMLog(verbose=True)
  >>> cm.monitor(2, 0.5)
  >>> _ = [i for i in range(10000000)]
  >>>
  >>> # Collecting before completion triggers a message but no error
  >>> cm._collect()
  >>>
  >>> sleep(2)
  >>> cm._collect()
  >>> print('CPU usage:')
  >>> cm.cpu
  [CMLog] Monitoring for 2 seconds with checks every 0.5 seconds.
  [CMLog] Job not finished. Cannot _collect yet.
  [CMLog] Collecting... done. Read 4 lines in 0.000 seconds.
  CPU usage:
  array([ 50. ,  22.4,   6. ,  11.9])
  
  Raises
  ------
  ImportError :
      Depends on psutil. If not installed, raises ImportError on
      instantiation.
  
  Parameters
  ----------
  verbose : bool
      whether to notify of job start.
docstr: Collect monitored data.
  
  Once a monitor job finishes, call ``_collect`` to read the CPU and
  memory usage into python objects in the current process. If called
  before the job finishes, _collect issues a print statement to try
  again later, but no warning or error is raised.
docstr_tok: ["Collect","monitored","data",".","Once","a","monitor","job","finishes",",","call","``","_collect","``","to","read","the","CPU","and","memory","usage","into","python","objects","in","the","current","process",".","If","called","before","the","job","finishes",",","_collect","issues","a","print","statement","to","try","again","later",",","but","no","warning","or","error","is","raised","."]
code: def collect(self):
      """Collect monitored data.
  
      Once a monitor job finishes, call ``_collect`` to read the CPU and
      memory usage into python objects in the current process. If called
      before the job finishes, _collect issues a print statement to try
      again later, but no warning or error is raised.
      """
      if not hasattr(self, "_stop"):
          safe_print(
              "No monitoring job initiated: nothing to _collect."
          )
          return
  
      if self._stop is None:
          # If no timer, kill process.
          self._out.kill()
  
          if self.verbose:
              safe_print("[CMLog] Collecting...", end=" ", flush=True)
  
      # Check if job is not completed and if so, check whether to kill
      elif time() - self._t0 < self._stop:
          if self._kill:
              if self.verbose:
                  safe_print(
                      "[CMLog] Job not finished - killing process "
                      "and collecting...",
                      end=" ",
                      flush=True,
                  )
              self._out.kill()
  
          elif self.verbose:
              # Wait until completion (this is done in the 'communicate'
              # command
              safe_print(
                  "[CMLog] Job not finished - waiting "
                  "until completion and collecting...",
                  end=" ",
                  flush=True,
              )
  
      # If job done, we just need to _collect
      elif self.verbose:
          safe_print("[CMLog] Collecting...", end=" ", flush=True)
  
      t0, i = time(), 0
      cpu, rss, vms = [], [], []
  
      out = self._out.communicate()
      out = out[0].decode().strip().split("\n")
      for line in out:
          c, r, v = line.split(",")
  
          cpu.append(float(c.strip()))
          rss.append(int(r.strip()))
          vms.append(int(v.strip()))
  
          i += 1
  
      if self.verbose:
          safe_print(
              "done. Read {} lines in "
              "{:.3f} seconds.".format(i, time() - t0)
          )
  
      self.cpu = array(cpu)
      self.vms = array(vms)
      self.rss = array(rss)
  
      # Clear job data
      del self._t0
      del self._stop
      del self._kill
  
      self._out.terminate()
      del self._out
  
imports: from __future__ import division, print_function, with_statement
  import os
  import sys
  import warnings
  import subprocess
  from numpy import array
  from ..config import get_ivals
  from .exceptions import ParallelProcessingError, ParallelProcessingWarning
  from time import sleep
label_desc: Use image node_id 3 for calling the CMLog obj's underlying member method code with example usage: obj.collect() without return types