Problems with Perl's Purple::timeout_add

Jens Frank jens.l.frank at googlemail.com
Wed Jun 16 08:57:33 EDT 2010


Hi,

I'm using the following code from the Perl plugin howto:

----------------

use Purple;
%PLUGIN_INFO = (
    perl_api_version => 2,
    name => "Timeoutbug",
    version => "0.1",
    summary => "Test plugin for the Perl interpreter.",
    description => "Your description here",
    author => "John H. Kelm <johnhkelm\@gmail.com",
    url => "http://pidgin.im",
    load => "plugin_load",
    unload => "plugin_unload"
);
sub plugin_init {
    return %PLUGIN_INFO;
}


sub timeout_cb {
    my $plugin = shift;
    Purple::Debug::info("testplugin", "Timeout occurred.\n");
    # Reschedule timeout
    Purple::timeout_add($plugin, 5, \&timeout_cb, $plugin);
}
sub plugin_load {
    $plugin = shift;
    # Schedule a timeout for ten seconds from now
    Purple::timeout_add($plugin, 1, \&timeout_cb, $plugin);
}

sub plugin_unload {
    my $plugin = shift;
    Purple::Debug::info("testplugin", "plugin_unload() - Test Plugin
Unloaded.\n");
}

---------------

When enabling the plugin, I get:

(14:42:08) *perl:* Loading perl script
(14:42:08) *prefs:* /pidgin/plugins/loaded changed, scheduling save.
(14:42:09) *testplugin:* Timeout occurred.
(14:42:10) *testplugin:* Timeout occurred.
(14:42:11) *testplugin:* Timeout occurred.
(14:42:12) *testplugin:* Timeout occurred.
(14:42:13) *testplugin:* Timeout occurred.
(14:42:14) *testplugin:* Timeout occurred.
(14:42:14) *testplugin:* Timeout occurred.
(14:42:15) *testplugin:* Timeout occurred.
(14:42:15) *testplugin:* Timeout occurred.
(14:42:16) *testplugin:* Timeout occurred.
(14:42:16) *testplugin:* Timeout occurred.
(14:42:17) *testplugin:* Timeout occurred.
(14:42:17) *testplugin:* Timeout occurred.
(14:42:18) *testplugin:* Timeout occurred.
(14:42:18) *testplugin:* Timeout occurred.
(14:42:19) *testplugin:* Timeout occurred.
(14:42:19) *testplugin:* Timeout occurred.
(14:42:19) *testplugin:* Timeout occurred.
(14:42:19) *testplugin:* Timeout occurred.
(14:42:20) *testplugin:* Timeout occurred.
(14:42:20) *testplugin:* Timeout occurred.
(14:42:20) *testplugin:* Timeout occurred.
(14:42:20) *testplugin:* Timeout occurred.
(14:42:21) *testplugin:* Timeout occurred.
(14:42:21) *testplugin:* Timeout occurred.
(14:42:21) *testplugin:* Timeout occurred.
(14:42:21) *testplugin:* Timeout occurred.
(14:42:22) *testplugin:* Timeout occurred.
(14:42:22) *testplugin:* Timeout occurred.
(14:42:22) *testplugin:* Timeout occurred.
(14:42:22) *testplugin:* Timeout occurred.
(14:42:23) *testplugin:* Timeout occurred.
(14:42:23) *testplugin:* Timeout occurred.
(14:42:23) *testplugin:* Timeout occurred.
(14:42:23) *testplugin:* Timeout occurred.
(14:42:24) *testplugin:* Timeout occurred.
(14:42:24) *testplugin:* Timeout occurred.
(14:42:24) *testplugin:* Timeout occurred.
(14:42:24) *testplugin:* Timeout occurred.
(14:42:24) *testplugin:* Timeout occurred.
(14:42:24) *testplugin:* Timeout occurred.
(14:42:24) *testplugin:* Timeout occurred.
(14:42:24) *testplugin:* Timeout occurred.
(14:42:25) *testplugin:* Timeout occurred.
(14:42:25) *testplugin:* Timeout occurred.
(14:42:25) *testplugin:* Timeout occurred.
(14:42:25) *testplugin:* Timeout occurred.
(14:42:25) *testplugin:* Timeout occurred.
(14:42:25) *testplugin:* Timeout occurred.
(14:42:25) *testplugin:* Timeout occurred.
(14:42:25) *testplugin:* Timeout occurred.
(14:42:26) *testplugin:* Timeout occurred.
(14:42:26) *testplugin:* Timeout occurred.
(14:42:26) *testplugin:* Timeout occurred.
(14:42:26) *testplugin:* Timeout occurred.
(14:42:26) *testplugin:* Timeout occurred.
(14:42:26) *testplugin:* Timeout occurred.
(14:42:26) *testplugin:* Timeout occurred.
(14:42:26) *testplugin:* Timeout occurred.
(14:42:26) *plugins:* Unloading plugin Timeout
(14:42:26) *perl:* Unloading perl script
(14:42:26) *testplugin:* plugin_unload() - Test Plugin Unloaded.

The callback gets registered with a 1 second timeout and gets executed after
a second, at 14:42:09. It re-registers itself with a 5s timeout. The
re-registered callback gets triggered at 14:42:14. That's what I've
expected.
What I don't understand: Why is the original 1s timeout still being
triggered every second? Why are all the 5s timeouts being called again and
again? After a few minutes, Pidgin uses 100% CPU and the UI freezes
completely due to the number of running callbacks.

The docs say that I have to re-register timeouts, they only get executed
once. If I remove the re-registering in sub timeout_cb, the callback is
called only once.

I'm using Pidgin 2.7.1 on Windows XP with ActivePerl 5.10.1 build 1007.

Best regards,

jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pidgin.im/pipermail/support/attachments/20100616/365619d3/attachment.html>


More information about the Support mailing list