Subject: | Crashes with no traceback - suspect something is happening on Twitter end you aren't dealing with |
I have a program that calls AnyEvent::Twitter::Stream to accumulate data
from the "sample" stream. That program is attached ("Sample.pl").
Environment is openSUSE 11.2 64-bit - I can dump the whole environment
details if you wish, but I think this is something Twitter is doing and
not your code. Here's the error message I'm getting:
ERROR: AnyEvent::Handle=HASH(0xd51738) at
/usr/lib/perl5/site_perl/5.10.0/AnyEvent/Twitter/Stream.pm line 102
runtime error in AnyEvent::guard callback: Can't call method "destroy"
on an undefined value at
/usr/lib/perl5/site_perl/5.10.0/AnyEvent/Twitter/Stream.pm line 122.
That's all I get - if there's a way to enable debugging so I can capture
more info when this happens, let me know. This is very rare - I started
this particular instance up at 2010-03-18 06:00:00 UTC and it crashed at
2010-03-22 13:29:35 UTC.
Show quoted text
> perl -v
This is perl, v5.10.0 built for x86_64-linux-thread-multi
Copyright 1987-2007, Larry Wall
Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
Show quoted text> uname -a
Linux AlgoCompSynth 2.6.31.12-0.1-desktop #1 SMP PREEMPT 2010-01-27
08:20:11 +0100 x86_64 x86_64 x86_64 GNU/Linux
I'm starting up another instance now.
Subject: | Sample.pl |
#!/usr/bin/perl -w
use strict;
use warnings;
use Carp;
use English qw(-no_match_vars);
use AnyEvent::Twitter::Stream;
use Sys::Statistics::Linux;
#use IO::Compress::Bzip2 qw(bzip2 $Bzip2Error) ;
# get a Linux stats handle
my $lxs = Sys::Statistics::Linux->new(
processes => {
init => 1,
pids => [ $$ ]
}
);
sleep 1;
my $cumulative_cpu = 0;
$cumulative_cpu = perfsnap($cumulative_cpu);
my $auth = `cat znmeb_filter.auth`;
my ($user, $password, $user_id) = split /:/, $auth;
my $stamp = timestamp();
open my $STATUS, '>>:utf8', "${stamp}.json" or croak $OS_ERROR;
my $done = AnyEvent->condvar;
my $handle = AnyEvent::Twitter::Stream->new(
username => $user,
password => $password,
method => 'sample',
no_decode_json => 1,
on_tweet => sub {
# test for file rollover
my $newstamp = timestamp();
if ($newstamp ne $stamp) {
$cumulative_cpu = perfsnap($cumulative_cpu);
close $STATUS or croak $OS_ERROR;
system "bzip2 -9 ${stamp}.json &";
$stamp = $newstamp;
open $STATUS, '>>:utf8', "${stamp}.json" or croak $OS_ERROR;
}
# route the JSON string to the filesystem
my $tweet = shift;
print {$STATUS} "${tweet}\n" or croak $OS_ERROR;
},
on_error => sub {
my $error = shift;
carp "ERROR: $error";
$done->send;
},
on_eof => sub {
$done->send;
},
);
$done->recv;
sub timestamp {
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime time;
my $timestamp = sprintf '%04d%02d%02d%02d', $year+1900, $mon+1, $mday, $hour;
return $timestamp;
}
sub perfsnap {
my ($cumulative_cpu) = @_;
my $stats = $lxs->get;
my $self = $stats->{processes}{$$};
my $cputime = $self->{ttime} + $cumulative_cpu;
my ($days, $hours, $minutes, $seconds) = split /:/, $self->{actime};
my $walltime = 86400.0*$days + 3600.0*$hours + 60.0*$minutes +
$seconds;
my $ratio = $cputime/$walltime;
printf STDERR "%.4f cpu, %.4f wall, %.4f ratio\n", $cputime, $walltime, $ratio;
return $cputime;
}