<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def application(self, app_id):
 """Update the context to use the given application ID and stop the application when done. For example:: with cn.application(54):
 # All commands in this block will use app_id=54. # On leaving the block `cn.send_signal("stop", 54)` is # automatically called. """

        # Get a new context and add a method that will be called before the
        # context is removed from the stack.
        context = self(app_id=app_id)
        context.before_close(lambda: self.send_signal("stop"))
        return context