Ok, here is how to do that , the threading communication setup
#!/usr/bin/perl -- use strict; use warnings; use threads; use Thread::Queue; my $qin = Thread::Queue->new(); my $qout = Thread::Queue->new(); my $guithread = threads->create( sub { require MyApp::GUI; ## MyApp/GUI.pm MyApp::GUI::WorkQ(@_); ## uses timer to check on queue }, $qin, $qout, ); my $dbithread = threads->create( sub { require MyApp::DBFetch; ## MyApp/DBFetch.pm MyApp::DBFetch::WorkQ(@_); }, $qin, $qout, ); $guithread->join; ## wait for gui to finish __END__

Then the background worker thread waits for instructions (jobs to do from $qin), and sends messages back (on $qout)

sub MyApp::DBFetch::WorkQ { my( $qin, $qout ) = @_; my %stash; while( defined( my $argRef = $qin->dequeue ) ) { my $action = delete $argRef->{action}; if( $action eq 'connect' ){ $stash{dbi} = DBI->...; $qout->enqueue( { status => 'you are connected' } ); } } }

Then the gui thread ... uses buttons to send jobs to worker thread, and sets up a timer to check for return messages from the worker thread

sub MyApp::GUI::WorkQ { my( $qin, $qout ) = @_; .... Glib::Timeout->add( 50, sub { CheckQ( $qout, $statuswindow} } ); Gtk2->main; } sub OnConnectButton { my( $qin, $passwindow ) = @_; my $password = $passwindow->get_text; ... $qin->enqueue( { action => 'connect', password => $password, ... } + ); } sub CheckQ { my( $qout, $statuswindow ) = @_; if( defined( my $ref = $qout->popnow ) ) { my $msg = $ref->{status}; $statuswindow->set_text( $msg ); } return 1; ## don't cancel timeout, repeat it }

Does that make sense? There are other ways to do threading, but its more complicated :) see What is the usage of "use Gtk2 -init -threads-init"? and https://metacpan.org/source/XAOC/Gtk2-1.2494/examples/thread_usage.pl and don't ask me about it :)


In reply to Re^3: xcb Unknown sequence number while processing queue in Perl/Gtk2 by Anonymous Monk
in thread xcb Unknown sequence number while processing queue in Perl/Gtk2 by Muskovitz

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.