<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _add_process_guards(self, engine):
 """Add multiprocessing guards. Forces a connection to be reconnected if it is detected as having been shared to a sub-process. """


        @sqlalchemy.event.listens_for(engine, "connect")
        def connect(dbapi_connection, connection_record):
            connection_record.info['pid'] = os.getpid()

        @sqlalchemy.event.listens_for(engine, "checkout")
        def checkout(dbapi_connection, connection_record, connection_proxy):
            pid = os.getpid()
            if connection_record.info['pid'] != pid:
                self.logger.debug(
                    "Parent process %(orig)s forked (%(newproc)s) with an open database connection, "
                    "which is being discarded and recreated." % {"newproc": pid, "orig": connection_record.info['pid']})
                connection_record.connection = connection_proxy.connection = None
                raise exc.DisconnectionError(
                    "Connection record belongs to pid %s, attempting to check out in pid %s" % (
                        connection_record.info['pid'], pid)
                )