Exemplo n.º 1
0
    def schedule_destroy_asap(self, post_delete_func=None, source=None, cause=None, **kwargs):

        def call_destroy(timeline):
            if services.reset_and_delete_service.can_be_destroyed(self):
                self.destroy(source=source, cause=cause, **kwargs)

        element = elements.CallbackElement(elements.FunctionElement(call_destroy), complete_callback=post_delete_func, hard_stop_callback=post_delete_func, teardown_callback=None)
        services.time_service().sim_timeline.schedule_asap(element)
Exemplo n.º 2
0
def _build_element(elem, sequence_wrapper=None):
    if isinstance(elem, functools.partial):
        canonical = elem.func
    else:
        canonical = elem
    if elem is None:
        return
    if isinstance(elem, elements.Element):
        return elem
    if isinstance(elem, (tuple, list)):
        return _build_from_iterable(elem, sequence_wrapper=sequence_wrapper)
    if inspect.isgeneratorfunction(canonical):
        return elements.GeneratorElement(elem)
    if inspect.isroutine(canonical):
        return elements.FunctionElement(elem)
    raise ValueError('Unknown element in _build_element: {}'.format(elem))
Exemplo n.º 3
0
def force_hang_with_irq(duration: int = 10000,
                        irq_interval=100,
                        _connection=None):
    duration /= MILLISECONDS_PER_SECOND
    interval = irq_interval / MILLISECONDS_PER_SECOND
    yield_to_irq = sims4.sim_irq_service.yield_to_irq

    def do_hang_fn(_):
        nonlocal duration
        output = sims4.commands.Output(_connection)
        output(
            'Simulation hanging for {0:.2f} seconds with irq interval of {1:.2f}'
            .format(duration, interval))
        while duration > 0:
            sleep_time = max(0.001, min(duration, interval))
            time.sleep(sleep_time)
            duration -= sleep_time
            yield_to_irq()
        output('Simulation resuming.'.format(duration))

    services.time_service().wall_clock_timeline.schedule(
        elements.FunctionElement(do_hang_fn))
    return True