Spreadsheet :: ParseExcel :: Stream丢失了解析器

时间:2013-10-01 17:19:01

标签: excel perl

我有一个18M Excel电子表格要解析,而Spreadsheet::ParseExcel耗费了大量内存,我不得不切换到Spreadsheet::ParseExcel::Stream。它在我的VM上工作正常,它在我们的登台服务器上工作正常,但在我们的生产服务器上(配置方式相同),我收到此错误:

Can't call method "transfer" on an undefined value at \
lib/Spreadsheet/ParseExcel/Stream/XLS.pm line 31.

来自以下代码:

my ($wb, $idx, $row, $col, $cell);
my $tmp = my $handler = sub {
  ($wb, $idx, $row, $col, $cell) = @_;
  $parser->transfer($main);  XXX here's where we die
};

my $tmp_p = $parser = Coro::State->new(sub {
  $xls->Parse($file);
  # Flag the generator that we're done
  undef $xls;
  # If we don't transfer back when done parsing,
  # it's an implicit program exit (oops!)
  $parser->transfer($main)
});
weaken($parser);

weaken看起来很可疑,所以除非refcount大于1,否则我试图不削弱,但同样的问题也会发生。我检测了代码以获得堆栈跟踪并得到了这个:

parser is undefined at lib/Spreadsheet/ParseExcel/Stream/XLS.pm line 29.

Spreadsheet::ParseExcel::Stream::XLS::__ANON__                   \
  ('Spreadsheet::ParseExcel::Workbook=HASH(0x6cd4a08)', 0, 2, 1, \
  'Spreadsheet::ParseExcel::Cell=HASH(0x1387ce78)') called at    \
  /usr/share/perl5/Spreadsheet/ParseExcel.pm line 2152
Spreadsheet::ParseExcel::_NewCell(                               \ 
  'Spreadsheet::ParseExcel::Workbook=HASH(0x6cd4a08)', 2, 1,     \
  'Kind', 'PackedIdx', 'Val', 'Dean', 'FormatNo', 25, ...)       \
   called at /usr/share/perl5/Spreadsheet/ParseExcel.pm line 896
Spreadsheet::ParseExcel::_subLabelSST(                           \
  'Spreadsheet::ParseExcel::Workbook=HASH(0x6cd4a08)', 253, 10,  \
  '\x{2}\x{0}\x{1}\x{0}\x{19}\x{0}2\x{0}\x{0}\x{0}')             \
   called at /usr/share/perl5/Spreadsheet/ParseExcel.pm line 292
Spreadsheet::ParseExcel::parse(                                  \
  'Spreadsheet::ParseExcel=HASH(0x6cd1810)', '2013-09-13.xls')   \
   called at lib/Spreadsheet/ParseExcel/Stream/XLS.pm line 35
Spreadsheet::ParseExcel::Stream::XLS::__ANON__                   \
   called at new_importer.pl line 0

这告诉我解析器读取第一行和第二行,但由于某种原因它在第三行死亡。

我尝试重建Spreadsheet::ParseExcel::Stream并且似​​乎没有任何错误(所有测试都通过)。我还重新编译了Coro(同样的结果)。

我很神秘。有人有什么想法吗?

1 个答案:

答案 0 :(得分:15)

问题变得相当奇怪,看起来像这个伪代码:

stream1 = open first excel stream
sheet1  = stream1.sheet // get spreadsheet ready for reading

if in verbose mode:
    stream2 = open second excel stream
    sheet2  = stream2.sheet
    count++ while sheet2.get_row
    say "We have $count records"

我们发现,当且仅当我们处于详细模式时才会出现此问题。通过让两个流指向同一个文档,我们的生产代码会失败,尽管这在其他框上运行良好。通过在打开常规流来读取文档之前计算行数并关闭该流,我们解决了这个问题。