Emit the client response if exists and die...
425521
public function emit()
    {
        if (headers_sent($file, $line)) {
            throw new \LogicException('Headers already sent in %s on line %d', $file, $line);
        }

        if ($this->getResponse()) {
            (new Response\SapiEmitter())->emit($this->getResponse());
            exit();
        }
    }
1266699
def emit_answer_event(sender, instance, **kwargs):
    
    if not issubclass(sender, Answer) or not kwargs['created']:
        return
    logger = get_events_logger()
    logger.emit('answer', {
        "user_id": instance.user_id,
        "is_correct": instance.item_asked_id == instance.item_answered_id,
        "context_id": [instance.context_id] if instance.context_id else [],
        "item_id": instance.item_id,
        "response_time_ms": instance.response_time,
        "params": {
            "session_id": instance.session_id,
            "guess": instance.guess,
            "practice_set_id": instance.practice_set_id,
            "config_id": instance.config_id,
        }}
    )
757472
function onResponse( response ) {
		if ( response.statusCode !== 200 ) {
			err = {
				'status': response.statusCode,
				'message': ''
			};
		}
		debug( 'Received a response from query endpoint.' );
		debug( 'Response status: %s.', response.statusCode );
		debug( 'Response headers: %s', JSON.stringify( response.headers ) );

		response.setEncoding( 'utf8' );
		response.on( 'data', onData );
		response.on( 'end', onEnd );
	}
1191298
def die(self):
        """"""
        if self.process:
            _log(self.logging,
                 'Stopping {0} server with PID: {1} running at {2}.'
                     .format(self.__class__.__name__, self.process.pid,
                             self.check_url))

            self._kill()
989734
def abort(self, err):
        """"""
        if _debug: IOQController._debug("abort %r", err)

        if (self.state == CTRL_IDLE):
            if _debug: IOQController._debug("    - idle")
            return

        while True:
            iocb = self.ioQueue.get(block=0)
            if not iocb:
                break
            if _debug: IOQController._debug("    - iocb: %r", iocb)

            # change the state
            iocb.ioState = ABORTED
            iocb.ioError = err

            # notify the client
            iocb.trigger()

        if (self.state != CTRL_IDLE):
            if _debug: IOQController._debug("    - busy after aborts")
239730
def send_response(self, code, message=None):
        """"""
        self.log_request(code)
        if message is None:
            message = code in self.responses and self.responses[code][0] or ""
        if self.request_version != "HTTP/0.9":
            hdr = "%s %d %s\r\n" % (self.protocol_version, code, message)
            self.wfile.write(hdr.encode("ascii"))
271002
async def listen(self):
        ""
        if self.subscribed:
            return self.handle_message(await self.parse_response(block=True))
763801
def respond_client(self, answer, socket):
        """"""
        response = pickle.dumps(answer, -1)
        socket.sendall(response)
        self.read_list.remove(socket)
        socket.close()
1242000
function(err) {
          console.log('SOCKET ' + command +
                      '(' + debugStr(request.data, 30) + ') Exception');
          util.errorHandler(err);

          socket.emit('reply', {
            id: request.id,
            exception: '' + err
          });
        }
1002608
def dead(self):
        
        if not self._weak:
            return False
        cb = self._callback()
        if cb is None:
            return True
        return False
388259
def kill_clients():
    """"""
    clients = request.form.get('clients').split(',')
    kill_dead = request.args.get('kill_dead', default=False)
    kill_dead = kill_dead and kill_dead in ['true', '1']

    if not kill_dead and not clients:
        return jsonify({'Error': 'no clients provided'})

    for client in list(drivers.keys()):
        if kill_dead and not drivers[client].is_logged_in() or client in clients:
            drivers.pop(client).quit()
            try:
                timers[client].stop()
                timers[client] = None
                release_semaphore(client)
                semaphores[client] = None
            except:
                pass

    return get_active_clients()
102540
async def execute_command(
        self, *args: bytes, timeout: DefaultNumType = _default
    ) -> SMTPResponse:
        
        if timeout is _default:
            timeout = self.timeout  # type: ignore

        self._raise_error_if_disconnected()

        try:
            response = await self.protocol.execute_command(  # type: ignore
                *args, timeout=timeout
            )
        except SMTPServerDisconnected:
            # On disconnect, clean up the connection.
            self.close()
            raise

        # If the server is unavailable, be nice and close the connection
        if response.code == SMTPStatus.domain_unavailable:
            self.close()

        return response
944381
def _fail(self, request_id, failure, duration):
        """"""
        self.listeners.publish_command_failure(
            duration, failure, self.name,
            request_id, self.sock_info.address, self.op_id)
1097866
def serve_forever(self):
        """"""

        # Test if client and server are in the same major version
        if not self.login():
            logger.critical("The server version is not compatible with the client")
            self.end()
            return self.client_mode

        exitkey = False
        try:
            while True and not exitkey:
                # Update the stats
                cs_status = self.update()

                # Update the screen
                if not self.quiet:
                    exitkey = self.screen.update(self.stats,
                                                 cs_status=cs_status,
                                                 return_to_browser=self.return_to_browser)

                # Export stats using export modules
                self.stats.export(self.stats)
        except Exception as e:
            logger.critical(e)
            self.end()

        return self.client_mode
1303790
function reply(req, res, timeout) {
  var _timer;

  if(timeout) {
    //console.dir(timeout);
    //console.error(Date.now());
    _timer = setTimeout(this.onTimeout, timeout);
    this._busy = true;
  }

  function onClose(code, signal) {
    //console.dir('close called: ' + signal);
    //console.dir(code);
    //console.dir(signal);
    this.ps.removeAllListeners();
    clearTimeout(_timer);
    this.ps = null;
    this._busy = false;
    this._written = false;
    var msg, err = new StoreError(
      null, 'script execution process exited with code: %s', code || 0);
    if(signal === 'SIGQUIT') {
      msg = 'error running script (call to %s): '
      msg += '@user_script: script killed by user with SCRIPT KILL';
      err = new StoreError(null, msg, this._script || 'user_script');
    }
    res.send(err);
  }

  function onMessage(msg) {
    var cmd, args;

    //console.dir(msg);

    // getting the current script name
    if(msg.event === 'eval') {
      this._script = msg.data;
      return;

    // calling out to execute a command
    }else if(msg.event === 'call') {
      req.cmd = msg.cmd;
      req.args = msg.args;

      //console.dir('got call event');

      var exec = this._commands[req.cmd];
      if(exec && exec.definition && exec.definition.write) {
        this._written = true;
        //console.dir('marking command as writing data...');
      }

      function onCommand(err, reply) {
        // restore req and res
        req.cmd = cmd;
        req.args = args;
        req.script = false;
        delete res.cb;

        var data = err ? err.message : reply;
        if(reply instanceof Buffer) reply = reply.toString();
        this.ps.send(
          {event: msg.event, err: (err instanceof Error), data: data});
      }

      req.script = true;

      res.cb = onCommand.bind(this);
      this.emit('command', req, res);
      //this.ps.once('message', onMessage.bind(this));
      return;
    }

    // ps may be null if script was killed
    if(this.ps) {
      this.ps.removeAllListeners();
    }

    clearTimeout(_timer);

    // sending data back to the client
    this._busy = false;
    this._written = false;
    var data = msg.data;
    if(msg.err) return res.send(new Error(data));
    if(msg.str) data = new String(data);
    return res.send(null, data);
  }

  this.ps.on('message', onMessage.bind(this));
  this.ps.once('close', onClose.bind(this));
}
563411
def _emit_message(cls, message):
        """"""
        sys.stdout.write(message)
        sys.stdout.flush()
710257
def __die(self, synchronous=False):
        
        if self.__id and not self.__killed:
            if self.__exhaust and self.__exhaust_mgr:
                # If this is an exhaust cursor and we haven't completely
                # exhausted the result set we *must* close the socket
                # to stop the server from sending more data.
                self.__exhaust_mgr.sock.close()
            else:
                address = _CursorAddress(
                    self.__address, self.__collection.full_name)
                if synchronous:
                    self.__collection.database.client._close_cursor_now(
                        self.__id, address)
                else:
                    self.__collection.database.client.close_cursor(
                        self.__id, address)
        if self.__exhaust and self.__exhaust_mgr:
            self.__exhaust_mgr.close()
        self.__killed = True