class_docstr: Metrics manager and batch writer 
class_docstr_tok: ["Metrics","manager","and","batch","writer"]
docstr: Write events to the backend, uploading any required files.
  :param events: A list of event objects
  :param async_enable: If True, upload is performed asynchronously and an AsyncResult object is returned,
      otherwise a blocking call is made and the upload result is returned.
  :param callback: A optional callback called when upload was completed in case async is True
  :return: .backend_api.session.CallResult if async is False otherwise AsyncResult. Note that if no events were
      sent, None will be returned.
docstr_tok: ["Write","events","to","the","backend",",","uploading","any","required","files",".",":","param","events",":","A","list","of","event","objects",":","param","async_enable",":","If","True",",","upload","is","performed","asynchronously","and","an","AsyncResult","object","is","returned",",","otherwise","a","blocking","call","is","made","and","the","upload","result","is","returned",".",":","param","callback",":","A","optional","callback","called","when","upload","was","completed","in","case","async","is","True",":","return",":",".backend_api.session.CallResult","if","async","is","False","otherwise","AsyncResult",".","Note","that","if","no","events","were","sent",",","None","will","be","returned","."]
code: def write_events(
      self, events, async_enable=True, callback=None, **kwargs
  ):
      """
      Write events to the backend, uploading any required files.
      :param events: A list of event objects
      :param async_enable: If True, upload is performed asynchronously and an AsyncResult object is returned,
          otherwise a blocking call is made and the upload result is returned.
      :param callback: A optional callback called when upload was completed in case async is True
      :return: .backend_api.session.CallResult if async is False otherwise AsyncResult. Note that if no events were
          sent, None will be returned.
      """
      if not events:
          return
  
      storage_uri = kwargs.pop("storage_uri", self._storage_uri)
  
      if not async_enable:
          return self._do_write_events(events, storage_uri)
  
      def safe_call(*args, **kwargs):
          try:
              return self._do_write_events(*args, **kwargs)
          except Exception as e:
              return e
  
      self._initialize_upload_pools()
      return self._upload_pool.apply_async(
          safe_call,
          args=(events, storage_uri),
          callback=partial(self._callback_wrapper, callback),
      )
  
imports: import json
  import os
  from functools import partial
  from logging import warning
  from multiprocessing.pool import ThreadPool
  from time import time
  from pathlib2 import Path
  from ...backend_api import Session
  from ...backend_api.services import events
  from ..base import InterfaceBase
  from ...config import config, deferred_config
  from ...debugging import get_logger
  from ...storage.helper import StorageHelper
  from .events import MetricsEventAdapter
  from ...utilities.process.mp import SingletonLock
label_desc: Use image node_id 5 for calling the Metrics obj's underlying member method code with example usage: obj.write_events(events, async_enable, callback) and returns: self, self, self, e