in reply to Re: Perl/Tk Multithreading
in thread Perl/Tk Multithreading

Without thread created on the concerned subroutine(run_script)that worked, but when I created thread on subroutine it is failing to do so which made me concluded it is not loading. Anyway now it is loading, but I am facing modules interface problem in the thread because the loaded file(add.pl) has different modules in it( example I am using Device::Modem::GSM module in add.pl). So when the thread is going into the modem file it is not able to call certain methods. It is giving error to call the methods on execution. And as you can see Device::Modem::GSM is built on other modules like Device::Modem, Device::Serialport. So the problem is getting complicated. If I make any changes in the Modem modules my application will not be portable on machines. Any solutions please.............

Replies are listed 'Best First'.
Re^3: Perl/Tk Multithreading
by BrowserUk (Patriarch) on Jul 17, 2011 at 15:18 UTC
    Any solutions please.............

    On the basis of the description so far. No.

    Will adding more words help. No.


    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.
      OK....I tried to give the simple example in the first post.. I thought I would explain what I am trying do in my code and what i want from it. Its true that 'do add.pl' didn't work at first but during this time I solved the problem. from beginning... 1. I am creating a thread 2. In the thread I called a function. 3. In the called function there is expression to load external perl file add.pl 4. The add.pl has network modules in it. (Example: use Device::Modem::GSM) Because of these modules the thread is ending abnormally. This where I am facing the present problem..... (Moreover I am not able format my post here)
        Because of these modules the thread is ending abnormally.

        That is not enough information for us to determine anything!

        This simple demo does all the steps you've outlined and works.

        This is the called .pl file that loads a module and uses it:

        #! perl -slw use strict; use Time::HiRes qw[ time sleep ]; print 'test.pl started loading'; sub doit { print 'doit called'; for( 1 .. 5 ) { print scalar time; sleep 1.5; } print 'doit() finished'; } print 'test.pl finished loading';

        And this is the program that loads that in a thread:

        #! perl -slw use strict; use threads; sub testit { do 'test.pl'; } async { print 'before testit()'; testit(); print 'after testit()'; doit(); }->join;

        And this is the result of running it:

        [18:40:12.57] C:\test>914924.pl before testit() test.pl started loading test.pl finished loading after testit() doit called 1310924420.797 1310924422.29803 1310924423.79802 1310924425.29802 1310924426.79802 doit() finished

        That took me about 45 seconds to write and run. Now how about you make some effort.


        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.
      So you say now you understood the problem on the basis of description....i understand you don't have solution....but atleast you think my problem is genuine or I am not able to explain properly

        Your descriptions are so jumbled and lacking in detail it is impossible to reach any conclusions based upon them.

        Your original post suggested that do "didn't work" when used in a thread. This is easily demonstrated to be untrue:

        c:\test>copy con test.pl print 'Hello from test.pl'; ^Z 1 file(s) copied. c:\test>perl -Mthreads -E"async{ do 'test.pl' }->join" Hello from test.pl c:\test>

        Now you say that is now working for you but "something else isn't working". That isn't much to go on!

        If your program is so large and has so many dependencies that you cannot post it here, then you need to produce a small, self contained example (like the one I just posted above), that demonstrates the problem you are having. Because your wordy descriptions mean absolutely nothing to me.

        The chances are, if you go through the process of writing a stand alone demo, you will probably realise your error yourself, but if you don't, the post it here and we'll be able to help you.


        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.
      So you say now you understood the problem on the basis of description....i understand you don't have solution....but atleast you think my problem is genuine or I am not able to explain properly