Writes an event proto to disk.

    This method is threadsafe with respect to invocations of itself.

    Args:
      event: The event proto.

    Raises:
      IOError: If writing the event proto to disk fails.
496017
def write_event(self, event):
    
    self._lock.acquire()
    try:
      self._events_writer.WriteEvent(event)
      self._event_count += 1
      if self._always_flush:
        # We flush on every event within the integration test.
        self._events_writer.Flush()

      if self._event_count == self._check_this_often:
        # Every so often, we check whether the size of the file is too big.
        self._event_count = 0

        # Flush to get an accurate size check.
        self._events_writer.Flush()

        file_path = os.path.join(self._events_directory,
                                 self.get_current_file_name())
        if not tf.io.gfile.exists(file_path):
          # The events file does not exist. Perhaps the user had manually
          # deleted it after training began. Create a new one.
          self._events_writer.Close()
          self._events_writer = self._create_events_writer(
              self._events_directory)
        elif tf.io.gfile.stat(file_path).length > self._single_file_size_cap_bytes:
          # The current events file has gotten too big. Close the previous
          # events writer. Make a new one.
          self._events_writer.Close()
          self._events_writer = self._create_events_writer(
              self._events_directory)
    except IOError as err:
      logger.error(
          "Writing to %s failed: %s", self.get_current_file_name(), err)
    self._lock.release()
20312
def send(self, event):
        # type(Event) -> bytes
        
        data = b""
        if isinstance(event, Request):
            data += self._initiate_connection(event)
        elif isinstance(event, AcceptConnection):
            data += self._accept(event)
        elif isinstance(event, RejectConnection):
            data += self._reject(event)
        elif isinstance(event, RejectData):
            data += self._send_reject_data(event)
        else:
            raise LocalProtocolError(
                "Event {} cannot be sent during the handshake".format(event)
            )
        return data
523715
def drive(self, event, *args):
        

        maps = self.base.get(event, self.step)
        for handle, data in maps[:]:
            params = args + data
            try:
                handle(self, *params)
            except Stop:
                break
            except StopIteration:
                pass
            except Kill as Root:
                raise
            except Erase:
                maps.remove((handle, data))
            except Exception as e:
                debug(event, params)

        for handle in self.pool:
            handle(self, event, args)
672153
def new_event(event):
    
    op_name = event.EventType.DESCRIPTOR.values_by_number[event.type].name
    if op_name == 'PUT':
        cls = PutEvent
    elif op_name == 'DELETE':
        cls = DeleteEvent
    else:
        raise Exception('Invalid op_name')

    return cls(event)
1294791
def add_event(self, event, prepend=False):
        
        if prepend:
            self._events.insert(0, event)
        else:
            self._events.append(event)
779589
def Open(self):
    
    if self._is_open:
      raise IOError('Storage writer already opened.')

    self._is_open = True

    self._first_written_event_source_index = len(self._event_sources)
    self._written_event_source_index = self._first_written_event_source_index
1266989
def publish_event(self, channel, event, message):
        '''
        '''
        assert self.protocol is not None, "Protocol required"
        msg = {'event': event, 'channel': channel}
        if message:
            msg['data'] = message
        return self.publish(channel, msg)
548317
def write_events(self, outname):
        
        self.make_output_dir(outname)

        if '.hdf' in outname:
            self.write_to_hdf(outname)
        else:
            raise ValueError('Cannot write to this format')
1313017
public void write(IRTMPEvent event) {
        if (!connection.isClosed()) {
            final IClientStream stream = connection.getStreamByChannelId(id);
            if (id > 3 && stream == null) {
                log.warn("Non-existant stream for channel id: {}, session: {} discarding: {}", id, connection.getSessionId(), event);
            }
            // if the stream is non-existant, the event will go out with stream id == 0
            final Number streamId = (stream == null) ? 0 : stream.getStreamId();
            write(event, streamId);
        } else {
            log.debug("Connection {} is closed, cannot write to channel: {}", connection.getSessionId(), id);
        }
    }
1295324
async def process_events_async(self, events):
        
        if events:
            # Synchronize to serialize calls to the processor. The handler is not installed until
            # after OpenAsync returns, so ProcessEventsAsync cannot conflict with OpenAsync. There
            # could be a conflict between ProcessEventsAsync and CloseAsync, however. All calls to
            # CloseAsync are protected by synchronizing too.
            try:
                last = events[-1]
                if last is not None:
                    self.partition_context.set_offset_and_sequence_number(last)
                    await self.processor.process_events_async(self.partition_context, events)
            except Exception as err:  # pylint: disable=broad-except
                await self.process_error_async(err)
727929
def PushEvent(self, event):
    
    macb_group_identifier, content_identifier = self._GetEventIdentifiers(event)

    # We can ignore the timestamp here because the psort engine only stores
    # events with the same timestamp in the event heap.
    heap_values = (macb_group_identifier or '', content_identifier, event)
    heapq.heappush(self._heap, heap_values)
1084077
def processEvent(cls, event):
        
        callbacks = cls.callbacks(type(event))
        keep_going = True
        remove_callbacks = []

        for callback, record, once in callbacks:
            if record is not None and record != event.record:
                continue

            callback(event)
            if once:
                remove_callbacks.append((callback, record))

            if event.preventDefault:
                keep_going = False
                break

        for callback, record in remove_callbacks:
            cls.removeCallback(type(event), callback, record=record)

        return keep_going
1268855
def write_event(self, event):
        """"""
        # Check if event is of type event_pb2.Event proto.
        if not isinstance(event, event_pb2.Event):
            raise TypeError("expected an event_pb2.Event proto, "
                            " but got %s" % type(event))
        return self._write_serialized_event(event.SerializeToString())
978413
def _make_event(self, event_type, code, value):
        """"""
        secs, msecs = convert_timeval(time.time())
        data = struct.pack(EVENT_FORMAT,
                           secs,
                           msecs,
                           event_type,
                           code,
                           value)
        self._write_device.write(data)
        self._write_device.flush()
288274
def record_event(self, event: Event) -> None:
        
        from polyaxon.celery_api import celery_app
        from polyaxon.settings import EventsCeleryTasks

        if not event.ref_id:
            event.ref_id = self.get_ref_id()
        serialized_event = event.serialize(dumps=False,
                                           include_actor_name=True,
                                           include_instance_info=True)

        celery_app.send_task(EventsCeleryTasks.EVENTS_TRACK, kwargs={'event': serialized_event})
        celery_app.send_task(EventsCeleryTasks.EVENTS_LOG, kwargs={'event': serialized_event})
        celery_app.send_task(EventsCeleryTasks.EVENTS_NOTIFY, kwargs={'event': serialized_event})
        # We include the instance in the serialized event for executor
        serialized_event['instance'] = event.instance
        self.executor.record(event_type=event.event_type, event_data=serialized_event)
296949
def write(self, byte):
        
        if self.is_closed_flag:
            raise Exception("Unable to write - already closed!")
        self.written += len(byte)
        self.file.write(byte)
1061526
def PushEvent(self, event):
    
    event_string = event.GetAttributeValuesString()
    heap_values = (event.timestamp, event.timestamp_desc, event_string, event)
    heapq.heappush(self._heap, heap_values)