def main():
    while not done:
        # garbage collect if pypy
        if python_implementation() == "PyPy":
            gc.collect_step()
        # add the past tick to the current time
        if not variables.generatingbeatmapp:
            variables.settings.current_time += clock.get_time()
        else:
            # set it to false, done generating
            variables.generatingbeatmapp = False
            # do not add the time to the clock
            clock.get_time()


        # --- Event Processing-
        for event in pygame.event.get():
            onevent(event)


        # --- Game Logic
        ontick()   

        # --- Drawing Code
        ondraw()

        # We want as many frames as possible to reduce likelyhood for mismatch with screen refresh and tearing
        clock.tick_busy_loop(0)
Exemple #2
0
def gc_tester():
    """Tests that an object is garbage collected.

  Yields a function that should be called with objects that may be part of a
  reference cycle.

  After the test function returns, verifies that any objects specified to the
  yielded function are garbage collected.
  """

    weak_refs: List[weakref.ref] = []

    def add_ref(obj: Any) -> None:
        # PyPy does not support `gc.is_tracked`.
        if hasattr(gc, "is_tracked"):
            assert gc.is_tracked(obj)
        weak_refs.append(weakref.ref(obj))

    yield add_ref

    gc.collect()
    if hasattr(gc, "collect_step"):
        # PyPy may require additional encouragement to actually collect the garbage.
        for _ in range(100):
            gc.collect_step()
    for ref in weak_refs:
        assert ref() is None
Exemple #3
0
def gc_collect_step(event):
    """ this calls the gc in a thread.
    """
    while True:
        # print '5) GC THREAD: Waiting to do gc.'
        event.wait()
        # print '4) GC THREAD: calling gc_collect_step'
        if hasattr(gc, "collect_step"):
            gc.collect_step()
        event.clear()
Exemple #4
0
    def on_gc_minor(self, stats):
        if self.nogc_count > 0:
            return

        # run the hook inside a nogc() section to avoid calling it
        # recursively. Else, it happens the following:
        #   1. a minor collection occurs, and we enter on_gc_minor
        #   2. we reached the threshold and start a major
        #   3. we call gc.collect_step
        #   4. internally, pypy does ANOTHER minor collection
        #   5. we enter AGAIN this hook
        #   6. we are major_in_progress, so we call another gc.collect_step
        #   7. and so on, until we finish the whole collection in one run :-(
        with self.nogc():
            if self.major_in_progress:
                step_stats = gc.collect_step()
                if step_stats.major_is_done:
                    self.major_in_progress = False
                    self.update_threshold(stats.total_memory_used)

            elif stats.total_memory_used > self.threshold:
                self.major_in_progress = True
                gc.collect_step()
Exemple #5
0
    def test_gc_collect_step(self):
        import gc

        class X(object):
            deleted = 0

            def __del__(self):
                X.deleted += 1

        gc.disable()
        X()
        X()
        X()
        n = 0
        while True:
            n += 1
            if gc.collect_step().major_is_done:
                break

        assert n >= 2  # at least one step + 1 finalizing
        assert X.deleted == 3