Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: WMI query with Threads

by BrowserUk (Pope)
on Feb 14, 2013 at 05:17 UTC ( #1018685=note: print w/ replies, xml ) Need Help??


in reply to Re^2: WMI query with Threads
in thread WMI query with Threads

i am sorry if i am wrong about crash. the reason, i said perl crashed was because i got a message window

That is kind of important information to have omitted from your post.

The good news is that I have reproduced your problem and have a solution for you.

The culprit is Win32::OLE. Even this simple threaded code that uses that module in the main thread, fails in exactly the same when when you try to join a thread. Even if that thread makes no use of the module:

#! perl -slw use strict; use threads; use Win32::OLE qw[ in with ]; my $thread = async { sleep 3; }; $thread->join;

However, if you require Win32::OLE in the thread(s) where you want to use it, it works fine:

#! perl -slw use strict; use threads; #use Win32::OLE qw[ in with ]; my $thread = async { require Win32::OLE; Win32::OLE->import( qw[ in with ] ); sleep 3; }; $thread->join;

So the solution to your immediate problem is to comment out the use Win32::OLE line at the top of your program and replace it with the require and import as shown above in the top of your thread subroutine.

Try that and see how you get on.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^3: WMI query with Threads
Select or Download Code
Re^4: WMI query with Threads
by Corion (Pope) on Feb 14, 2013 at 07:54 UTC

    Personally, I would try to avoid mixing threads and Win32::OLE, as I fear to omit relevant parts of the dance described in the documentation for Win32::OLE->Initialize(). I would look at the WMI command line tool wmic.exe as an alternative approach to multiprocessing, and launch that from multiple threads. There is some documentation in the MS technet.

      I would try to avoid mixing threads and Win32::OLE, as I fear to omit relevant parts of the dance described in the documentation for Win32::OLE->Initialize().

      I'm aware that running multiple instances of OLE in separate threads may not make for complete isolation even using require, but the failure appeared to be rooted entirely in Perl code rather than the underlying DLL's (which by default are initialised for multithreading).

      Hence requireing it into each thread does appear to provide isolation at the perl level; at least as far as the few trivial tests I've done go. It certainly fixes up the free to wrong pool error that was the cause of his headline problem.

      Over the years I've found several modules that "aren't threadsafe" work just fine if you require them into the thread where they are used rather than letting them be duplicated there at thread creation time. Usually I advocate only requiring them into a single thread, at which point they do not see any difference between being one thread is a multi threaded process and the only thread in a single threaded process; but in this case I thought I try requiring into multiple threads and it seems to work. (Maybe I should go back and try the same thing with some others; like Tk).

      I guess we'll find out if the OP ever gets back to us.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^4: WMI query with Threads
by vamsinm (Initiate) on Mar 04, 2013 at 14:44 UTC
    Sorry for the delay in reply. i was stuck with few other tasks to complete and did not get chance to work on this. i just tested this and it worked fine. thank you sooo much for your help!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2014-07-13 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (246 votes), past polls