class_docstr: 用来初始化 `Driver` 的基类，所有定制的 `driver` 都需要继承此类；
  **fastNLP** 提供的 driver 实例都会同时被 :class:`~fastNLP.core.controllers.Trainer` 和 :class:`~fastNLP.core.controllers.Evaluator` 调用。
  
  :param model: 训练或者评测的模型，需要注意该模型可能为用户已经使用类似 :class:`torch.nn.DataParallel` 或者
      :class:`torch.nn.parallel.DistributedDataParallel` 包裹过的模型。
class_docstr_tok: ["\u7528\u6765\u521d\u59cb\u5316","`","Driver","`","\u7684\u57fa\u7c7b\uff0c\u6240\u6709\u5b9a\u5236\u7684","`","driver","`","\u90fd\u9700\u8981\u7ee7\u627f\u6b64\u7c7b\uff1b","*","*","fastNLP","*","*","\u63d0\u4f9b\u7684","driver","\u5b9e\u4f8b\u90fd\u4f1a\u540c\u65f6\u88ab",":","class",":","`","~fastNLP.core.controllers.Trainer","`","\u548c",":","class",":","`","~fastNLP.core.controllers.Evaluator","`","\u8c03\u7528\u3002",":","param","model",":","\u8bad\u7ec3\u6216\u8005\u8bc4\u6d4b\u7684\u6a21\u578b\uff0c\u9700\u8981\u6ce8\u610f\u8be5\u6a21\u578b\u53ef\u80fd\u4e3a\u7528\u6237\u5df2\u7ecf\u4f7f\u7528\u7c7b\u4f3c",":","class",":","`","torch.nn.DataParallel","`","\u6216\u8005",":","class",":","`","torch.nn.parallel.DistributedDataParallel","`","\u5305\u88f9\u8fc7\u7684\u6a21\u578b\u3002"]
docstr: 该函数用于在训练或者预测过程中出现错误时正确地关掉其它的进程，这一点是通过在多进程 driver 调用 :meth:`open_subprocess` 的时候将每一个进程
  的 pid 记录下来，然后在出现错误后，由出现错误的进程手动地将其它进程 kill 掉。
  
  因此，每一个多进程 driver 如果想要该函数能够正确地执行，其需要在自己的 :meth:`open_subprocess` （开启多进程的函数）中正确地记录每一个进程的
  pid 的信息；单卡 driver 不需要这个函数。
docstr_tok: ["\u8be5\u51fd\u6570\u7528\u4e8e\u5728\u8bad\u7ec3\u6216\u8005\u9884\u6d4b\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u9519\u8bef\u65f6\u6b63\u786e\u5730\u5173\u6389\u5176\u5b83\u7684\u8fdb\u7a0b\uff0c\u8fd9\u4e00\u70b9\u662f\u901a\u8fc7\u5728\u591a\u8fdb\u7a0b","driver","\u8c03\u7528",":","meth",":","`","open_subprocess","`","\u7684\u65f6\u5019\u5c06\u6bcf\u4e00\u4e2a\u8fdb\u7a0b","\u7684","pid","\u8bb0\u5f55\u4e0b\u6765\uff0c\u7136\u540e\u5728\u51fa\u73b0\u9519\u8bef\u540e\uff0c\u7531\u51fa\u73b0\u9519\u8bef\u7684\u8fdb\u7a0b\u624b\u52a8\u5730\u5c06\u5176\u5b83\u8fdb\u7a0b","kill","\u6389\u3002","\u56e0\u6b64\uff0c\u6bcf\u4e00\u4e2a\u591a\u8fdb\u7a0b","driver","\u5982\u679c\u60f3\u8981\u8be5\u51fd\u6570\u80fd\u591f\u6b63\u786e\u5730\u6267\u884c\uff0c\u5176\u9700\u8981\u5728\u81ea\u5df1\u7684",":","meth",":","`","open_subprocess","`","\uff08\u5f00\u542f\u591a\u8fdb\u7a0b\u7684\u51fd\u6570\uff09\u4e2d\u6b63\u786e\u5730\u8bb0\u5f55\u6bcf\u4e00\u4e2a\u8fdb\u7a0b\u7684","pid","\u7684\u4fe1\u606f\uff1b\u5355\u5361","driver","\u4e0d\u9700\u8981\u8fd9\u4e2a\u51fd\u6570\u3002"]
code: def on_exception(self):
      r"""
      该函数用于在训练或者预测过程中出现错误时正确地关掉其它的进程，这一点是通过在多进程 driver 调用 :meth:`open_subprocess` 的时候将每一个进程
      的 pid 记录下来，然后在出现错误后，由出现错误的进程手动地将其它进程 kill 掉。
  
      因此，每一个多进程 driver 如果想要该函数能够正确地执行，其需要在自己的 :meth:`open_subprocess` （开启多进程的函数）中正确地记录每一个进程的
      pid 的信息；单卡 driver 不需要这个函数。
      """
      # 单卡 driver 不需要这个函数；
      if self._pids is not None:
          exc_type, exc_value, exc_traceback_obj = sys.exc_info()
          _write_exc_info = {
              "exc_type": str(exc_type.__name__),
              "exc_value": str(exc_value),
              "exc_time": str(
                  datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
              ),
              "exc_global_rank": getattr(self, "global_rank", None),
              "exc_local_rank": self.get_local_rank(),
          }
          sys.stderr.write("\nException info:\n")
          sys.stderr.write(json.dumps(_write_exc_info, indent=2) + "\n")
  
          sys.stderr.write(
              f"Start to stop these pids:{self._pids}, please wait several seconds.\n"
          )
          for pid in self._pids:
              if pid != os.getpid():
                  os.kill(pid, signal.SIGKILL)
  
imports: import os
  import signal
  import sys
  from typing import Sequence, List, Optional, Callable, Dict, Union, Tuple
  from abc import ABC, abstractmethod
  from datetime import datetime
  from pathlib import Path
  from io import BytesIO
  import json
  from fastNLP.core.utils import nullcontext
label_desc: Use image node_id 37 for calling the Driver obj's underlying member method code with example usage: obj.on_exception() without return types