I lost my "bless"ing. might have a clue

.... i just hack at these things... but the first thing i would try is avoid the intermediary $twit, directly put it into the shared hash

$thread_hash{'twit'} = Net::Twitter->new( username => $user, password => $pass );

.... another trick is to confine all your Twitter stuff to the thread.... is there really a need to keep a global twitter object?..... just put all the twitter stuff into the thread....

....with a sleeping thread model, as in Reusable threads demo .... and here is a Tk example with threads....notice the thread is created before any GUI code is invoked...... this goes along way toward making threaded GUI's work

#!/usr/bin/perl use strict; use Tk; use threads; use threads::shared; my $data_out:shared = ''; my $data_in:shared = ''; my $thread_die = 0; my $wthr = threads->new( \&update_thread )->detach; #create Tk stuff my $mw = MainWindow->new( -background => 'black', -foreground => 'yellow', -title => "Thread Test" ); $mw->geometry("600x400"); $mw->minsize( 400, 400 ); $mw->maxsize( 800, 800 ); my $sent_text = $mw->Scrolled('Text', -height => 10, -width => 60, -background => 'black', -foreground => 'yellow' )->pack( -side => 'bottom', -anchor => 's', -pady => 2 ); my $received_text = $mw->Scrolled( "Text", -height => 10, -width => 60, -background => 'white', -foreground => 'black', )->pack(); my $repeater = $mw->repeat(1000, sub{ $data_out++; $sent_text->insert( 'end', "Sent $data_out\n" ); $sent_text->see('end'); $received_text->insert( 'end', "Received $data_in\n" ); $received_text->see('end'); }); $mw->Button(-text=> 'Exit', -command => sub{ $thread_die = 1; $repeater->cancel; $mw->withdraw; kill 9, $$; })->pack; MainLoop; ######################################################### #the non-Tk worker code sub update_thread { print "update_thread called...\n"; while (1) { if($thread_die == 1){return} $data_in = 'thread-processing'.$data_out; sleep 1; } }

GUI's are notorious for having problems with threads..... another no-no with gui's is you can't manipulate the GUI (access widgets) in the main thread from the spawned thread..... Gtk2 has made a great improvement in this aspect, by the GLib::Idle_add method, which you can call from a spawned thread..... google for "glib idle_add" if interested..... Wx may have the idle_add method, since many systems use Gtk2 as the base for Wx.... but not always.


I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

In reply to Re: passing shared blessed object part 2 by zentara
in thread passing shared blessed object part 2 by Anonymous Monk

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.