I'm not experienced with the ins and outs out Wx, but look at Reusable threads demo for the basic CLI use. Then in your Wx gui, replace the while loops in the main thread, with Wx timers, etc.

But I can see from your example that you are starting the thread from a Wx button callback:

EVT_BUTTON($self,$self->{button_start}, \&DeployTestThread );
The general rule is to start the thread BEFORE any Wx gui code is invoked. So you may try something like
# Prevents double detach attempts my $DETACHING :shared; #start your thread here before Wx DeployTestThread(); package MyApp;
then your button callback will just set the shared variable
EVT_BUTTON($self,$self->{button_start}, sub{ $TERM = 0 } );
That's the idea, of course you need to setup $TERM properly. But that is the general idea of how to start the thread before the gui code, then use the gui to change a shared variable, which controls thread state.

For what it's worth, Perl/Gtk2 has a thread safety mechanism, and you can do what you are trying to do in Gtk2. Also, when Wx builds itself, it will use Gtk2 or Xlib as it's base objects. So if your Wx was built on Gtk2, you may be able to invoke the Glib thread safety mechanism in Wx. You will need to search the docs, or ask someone more knowledgable than me about Wx.


I'm not really a human, but I play one on earth CandyGram for Mongo

In reply to Re^4: Wx subs and threads by zentara
in thread Wx subs and threads 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.