Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Re:(wog) Win32::Gui + Threading?

by Flame (Deacon)
on Nov 13, 2001 at 03:29 UTC ( [id://124943]=note: print w/replies, xml ) Need Help??


in reply to Re: Re:(wog) Win32::Gui + Threading?
in thread Win32::Gui + Threading?

Oh, another question... how do I force a forked process to exit when the main program does?




-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
------END GEEK CODE BLOCK------
Translate

"Weird things happen, get used to it."

Flame ~ Lead Programmer: GMS

  • Comment on Re: Re: Re:(wog) Win32::Gui + Threading?

Replies are listed 'Best First'.
Re: Re: Re: Re:(wog) Win32::Gui + Threading?
by wog (Curate) on Nov 13, 2001 at 03:41 UTC
    What you probably should do is send a "special" message to the forked process (like you would send URLs, etc.) that will cause it to exit.
      I've tried this (based upon several examples... I really still don't understand what most of this is doing...):
      pipe(FROM_P, TO_C) or die "pipe: $!"; select(((select(TO_C), $| = 1))[0]); if (!(my $pid = fork)){ close(TO_C); #close(FROM_C); my $running = 1; while(my $line = <FROM_P>) { Win32::GUI::MessageBox(0,"Child Pid $$ just read this: $line","G +MS Alert"); chomp($line) if($line =~ m/\n$/o); if(lc($line) eq 'exit'){ Win32::GUI::MessageBox(0,"Exit","GMS"); sleep(20); #To allow time to read the MessageBox... if it eve +r comes up... exit; } } }


      Later on, these two subs deal with the exiting of the main program:
      sub GMSMain_Terminate { defined(my $win = $Win32::GUI::Loft::window{GMSMain}) or return(1); print TO_C 'exit'; return(-1); } sub mnuFileExit_Click { defined(my $win = $Win32::GUI::Loft::window{GMSMain}) or return(1); print TO_C 'exit'; return(-1); }


      When running it, however, I can exit part of it (the gui part) but it remains visible and perl itself keeps running. There is no message box popping up from the other process either.

      I'm probably making a rather stupid mistake, so please point it out if I am.


      -----BEGIN GEEK CODE BLOCK-----
      Version: 3.12
      GIT d- s:++ a--- C++++ UL P+++>++++ L+ E- W++>+++ N !o K- w+ O---- M-- V--
      PS PE Y- PGP t++(+++) 5(+++)++++ X R+@ tv+ b+++ DI+ D- G e->+++ h! r-- y-
      ------END GEEK CODE BLOCK------
      Translate

      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS

        Your problem is probably derived from trying to use the GUI from two threads. Don't do that. In your case what is probably happening is that when the forked process trys to pop-up its message box, the Win32::GUI event loop isn't running (since it just exited) so nothing happens.

        I advise against using Win32::GUI from multiple threads because Win32::GUI stores it's data in shared (not-thread-specific) variables (at the C level), so race conditions could easily cause crashes if you do not restrain from using it in only one thread.

        update: I have neglected to give an explanation as to why perl sticks around. I cannot think of a reason for it to not terminate after 20 seconds, unless Win32::GUI::MessageBox blocks, which would explain it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://124943]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-23 22:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found