In the following code, if I comment out the calls to InitAsterisk and DoneAsterisk, MainLoop exits as expected. however, if I leave the calls in place, MainLoop never exits. ("1" is never printed, and a ctrl-C is needed to get a prompt back.

Normally, I would put the Init first, and the Done in the Exit sub, but I did this to show that simply calling InitAsterisk causes the problem. Even if the data is wrong and no connection is made to the AMI, the behavior is the same.

What have I done wrong? (karma aside)
use Tk; use Asterisk::AMI::Common; my %config = ( user => "abuser", host => '192.168.1.22', secret => 'guessnot', port => '5038', ); &InitAsterisk; &DoneAsterisk; $top = MainWindow->new(); $button1 = $top->Button( -text => 'Exit', -command => sub { $top->des +troy; },)->pack; print "\n0\n"; MainLoop(); print "\n1\n"; exit; ############################################################ sub InitAsterisk { $asterisk = Asterisk::AMI->new(PeerAddr => $config{host}, PeerPort => $config{port}, Username => $config{user}, Secret => $config{secret}, ); die "Unable to connect to asterisk" unless ($asterisk); print "Asterisk connected\n"; } ############################################################ sub DoneAsterisk { print $asterisk->disconnect; print $asterisk->destroy; print "Asterisk disconnected\n"; die "Unable to DISCONNECT " unless ($asterisk); }
Ubuntu 10.04

In reply to Tk Mainloop - no exit. by Laotsu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.