class 队列的 superclass 不匹配(TypeError)

superclass mismatch for class Queue (TypeError)

当 运行 为 analyze.rb script from Univa Grid Engine Open Core 时,我得到一个 TypeError:

$ ./analyze.rb 
./analyze.rb:214:in `<main>': superclass mismatch for class Queue (TypeError)

该脚本是为 Ruby 1.8.1 开发的,但我使用的是更新的版本:

$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
$ uname -a
Linux <hostname> 2.6.32-642.4.2.el6.x86_64 #1 SMP Mon Aug 15 02:06:41 EDT 2016 x86_64 x86_64 x86_64 GNU/Linux
$ head -n1 /etc/issue
Red Hat Enterprise Linux Server release 6.8 (Santiago)

我已经打开了a GitHub issue,但是repro上的最后一个activity是6年前的,所以我也在这里问。

编辑:

如果我将 Ruby 版本降级到 1.9.3TypeError 就会消失...

$ conda uninstall ruby
Fetching package metadata .......
Solving package specifications: ..........

Package plan for package removal in environment /tools/general/app/anaconda-python-3.4/envs/accounting:

The following packages will be REMOVED:

    ruby: 2.2.3-0 bioconda

Proceed ([y]/n)? y

Unlinking packages ...
[      COMPLETE      ]|###############################################################################################################| 100%

$ conda install -c kalefranz ruby=1.9
Fetching package metadata .........
Solving package specifications: ..........

Package plan for installation in environment /tools/general/app/anaconda-python-3.4/envs/accounting:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    libffi-3.2.1               |                1          38 KB
    ncurses-5.9                |                5         640 KB  kalefranz
    ruby-1.9.3.551             |                0        12.8 MB  kalefranz
    ------------------------------------------------------------
                                           Total:        13.4 MB

The following NEW packages will be INSTALLED:

    libffi:  3.2.1-1              
    ncurses: 5.9-5       kalefranz
    ruby:    1.9.3.551-0 kalefranz

Proceed ([y]/n)? y

Fetching packages ...
libffi-3.2.1-1 100% |############################################################################################| Time: 0:00:00 852.02 kB/s
ncurses-5.9-5. 100% |############################################################################################| Time: 0:00:01 504.77 kB/s
ruby-1.9.3.551 100% |############################################################################################| Time: 0:00:22 606.26 kB/s
Extracting packages ...
[      COMPLETE      ]|###############################################################################################################| 100%
Linking packages ...
[      COMPLETE      ]|###############################################################################################################| 100%
$ ruby -v
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
$ ruby ./analyze.rb 
usage: analyze.rb <options> accounting_file
        -help
        -r                                records table
        -u                                users table
        -h                                hosts table
        -par                              parallel environment table
        -q                                queues table
        -p                                projects table
        -c                                categories table
        -ts                               timesteps table
        -ts_c                             categories per timestep
        -ts_j                             jobs per timestep
        -t "first"|<first> "last"|<last>  full analysis, but print these timesteps only

...但是当我尝试处理会计文件时,弹出其他错误:

$ ./analyze.rb -ts /gridware/uge/default//common/accounting 
invalid record 14473350 submitted 1503752102682 started 0 ended 0 wallclock 0
invalid record 14473350 submitted 1503752102682 started 0 ended 0 wallclock 0
invalid record 14473350 submitted 1503752102682 started 0 ended 0 wallclock 0
invalid record 14473350 submitted 1503752102682 started 0 ended 0 wallclock 0
invalid record 14473350 submitted 1503752102682 started 0 ended 0 wallclock 0
./analyze.rb:151:in `split': invalid byte sequence in UTF-8 (ArgumentError)
    from ./analyze.rb:151:in `block in initialize'
    from ./analyze.rb:149:in `each_line'
    from ./analyze.rb:149:in `initialize'
    from ./analyze.rb:557:in `new'
    from ./analyze.rb:557:in `read_records'
    from ./analyze.rb:774:in `<main>'

脚本添加一个 class Queue 像这样:

class Queue < Debitable 
end

Ruby 2.1 引入了自己的 Queue class 继承自 Object。这会导致您提到的错误。

以下脚本演示了问题:

class Thing < Object
end

class Thing < String
end

如果你运行它然后Ruby会告诉你它有一个superclass mismatch for class Thing (TypeError)

两种解决方法:

  • 使用 Ruby < 2.1 所以 Queue class 不存在(有点遗憾,不推荐)
  • 更新脚本,将所有出现的 Queue 替换为 MyQueue(您可以随意想出一个更好的名字)

一个 6 年前的脚本可能还包含其他问题......祝你好运。

此外:如果您确实需要不同的 ruby 版本,您可以查看 ruby 版本管理器,例如 RVM 或 RBEnv。