4

The thread module for PERL does not seem to work with Irssi. I can't get more information on this because the folk at #Irssi never respond.

I need to have the script check a database every 5 minutes. Now I thought this would be possible with multi-threading in PERL, but once you include the module Irssi will thrown an Exception.

Ironically, if I try and construct a while loop that terminates itself after a set amount of time the Irssi client just hangs.

Any suggestions?

Code

    use strict;
    use warnings;
    use threads;
    use Thread::Queue;

my $q = Thread::Queue->new();    # A new empty queue
    # Worker thread
    my $thr = threads->create(
        sub {
            # Thread will loop until no more work
            while (defined(my $item = $q->dequeue())) {
                # Do work on $item
            }
        }
    );

Errors in Irssi (not all of them, but same thing, cant locate package):

13:30| Can't locate package Irssi::ServerSetup for
          @Irssi::Irc::ServerSetup::ISA at
          /home/nullby7e/.irssi/scripts/test.pl line 27.
13:30|
13:30| Can't locate package Irssi::Nick for @Irssi::Irc::Nick::ISA at
          /home/nullby7e/.irssi/scripts/test.pl line 27.
13:30|
13:30| Can't locate package Irssi::ServerConnect for
          @Irssi::Irc::ServerConnect::ISA at
          /home/nullby7e/.irssi/scripts/test.pl line 27.
NullBy7e
  • 536
  • 9
  • 23

1 Answers1

0

I can't help you with threads, but according to Irssi Perl Scripting Reference you want the Irssi::timeout_add function.

You can find many examples how to use it at Irssi's Script Repository. Basic usage is:

use Irssi;

sub check_database {
    ...
}

Irssi::timeout_add(5*60*1000, "check_database", undef);
tom_14159
  • 74
  • 3