<commit_before>begin
  require 'tk'
rescue LoadError
  STDERR.puts 'Please install Tk Bindings for ruby first'
  exit
end

module GameOfLife
  module Renderers
    class TK
      def initialize
        @cell_size = 5
        @_tmp = {}
      end

      def run
        get_sizes
        tk_setup
        world_setup
        #@tk_loop.join
        #@world_loop.join
        world_render
      end

      def world_setup
        @world = GameOfLife::World.new(@height / @cell_size, @width / @cell_size, )

        #@world_loop = Thread.new { world_render }
      end

      def world_render
        loop do
          @world.cells.each_with_index do |col, x|
            col.each_with_index do |_cell, y|
              _x = x * @cell_size
              _y = y * @cell_size
              tmp_key = <KEY>
              if _cell.alive?
                @_tmp[tmp_key] = cell(_x, _y, _x + @cell_size, _y + @cell_size)
              else
                if @_tmp[tmp_key]
                  canvas.delete(@_tmp[tmp_key])
                  @_tmp[tmp_key] = nil
                end
              end
            end
          end
          @world.next!
        end
      end<commit_msg>run world in thread, exit tread on exception<commit_after>begin
  require 'tk'
rescue LoadError
  STDERR.puts 'Please install Tk Bindings for ruby first'
  exit
end

module GameOfLife
  module Renderers
    class TK
      def initialize
        @cell_size = 5
        @_tmp = {}
      end

      def run
        get_sizes
        tk_setup
        world_setup
        @world_loop.join
      end

      def world_setup
        @world = GameOfLife::World.new(@height / @cell_size, @width / @cell_size, )

        @world_loop = Thread.new { world_render }
        @world_loop.abort_on_exception = true
      end

      def world_render
        loop do
          @world.cells.each_with_index do |col, x|
            col.each_with_index do |_cell, y|
              _x = x * @cell_size
              _y = y * @cell_size
              tmp_key = <KEY>
              if _cell.alive?
                @_tmp[tmp_key] = cell(_x, _y, _x + @cell_size, _y + @cell_size)
              else
                if @_tmp[tmp_key]
                  canvas.delete(@_tmp[tmp_key])
                  @_tmp[tmp_key] = nil
                end
              end
            end
          end
          @world.next!
        end
      end
{'fraction_non_alphanumeric': 0.07608238755779739, 'fraction_numerical': 0.0008406893652795292, 'mean_word_length': 1.3634558093346574, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '797025', 'n_tokens_mistral': 764, 'n_tokens_neox': 735, 'n_words': 184}