#!/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__ #### 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' } ); } } } #### 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 }