[Dev] Test script with concurrent threads

William Martínez Pomares wmartinez at AVANTICATEC.NET
Thu May 24 11:32:38 PDT 2007


Well, that is a step forward.
 
runTest() is now being called inside the thread. That is good.  
The second parameter to start_new_thread() is a tuple that should contain the arguments for the method you pass on. In your code, you are sending (i,), which means you are sending one parameter (the value of variable i).
 
Now, since in the original code you were executing "test.runTest()" and it was actually executing, that means runTest does not need any argument!  Any class method always receives the "self" parameter and any other parameter you pass.  If you pass (i,), the thread will call test.runTest(self, i). The error then makes sense, it says it is receiving 2 arguments but was expecting 1. 
 
If what I suspect is true, then your call should be "thread.start_new_thread( test.runTest, ())". note the empty parenthesis in the second argument.
 
Second try! Good Luck!
 
William Martínez Pomares
R&D Manager and Architect 
Avantica Technologies
Phone(US)  :+1 (650) 353-4522  Ext 131 
Fax(US)        :+1 (877) 372-1955  
Phone(CR)  :+506 283-9100 Ext 131 
Fax(CR)        :+506 253-7451 
http://www.avantica.net <http://www.avantica.net/>  

-----Original Message-----
From: dev-bounces at lists.pushtotest.com [mailto:dev-bounces at lists.pushtotest.com]On Behalf Of Filipa Martins Soares Abrantes
Sent: Thursday, May 24, 2007 12:23 PM
To: PushToTest TestMaker Developers List
Subject: Re: [Dev] Test script with concurrent threads


Thank you William for your response.
 
I've executed without the parenthesis, like thread.start_new_thread( test.runTest, (i,)),  but now I'm getting the following error:
 

Traceback (innermost last):

  (no code object) at line 0

TypeError: runTest() too many arguments; expected 1 got 2



 
Any idea?
 
Thanks,
 
Filipa
 
On 5/24/07, William Martínez Pomares < wmartinez at avanticatec.net> wrote: 

Hi Filipa.
 
Sorry for the late response. Since this is the third post without answer, I thought I take a look althought I'm not a Python expert.
 
I found something in the line "thread.start_new_thread( test.runTest(), (i,))" but I'm not sure. 
As I understand from what I just read in internet, the start_new_thread() method receives two parameters: a method and a tuple with arguments to pass to the method. 
 
That means, the first parameter is the method you want to call. But, you don't need to call it, you just need to pass the method. In the line above, you are actually executing test.runTest() due to the parenthesis!
I think the line should be: "thread.start_new_thread( test.runTest, (i,))", note there are no parenthesis in runTest. 
With your line, you are first executing runTest(), and the result is passed to start_new_thread().  If runTest() returns a method, then the call is correct, but I think that is not your case. 
 
Please remove the parenthesis from runTest and try it, then let me know if it works. Again, I'm not an expert, so good luck.

 
William Martínez Pomares
R&D Manager and Architect 
Avantica Technologies
Phone(US)  :+1 (650) 353-4522  Ext 131 
Fax(US)        :+1 (877) 372-1955  
Phone(CR)  :+506 283-9100 Ext 131 
Fax(CR)        :+506 253-7451 
http://www.avantica.net <http://www.avantica.net/>  



-----Original Message-----
From: dev-bounces at lists.pushtotest.com [mailto: dev-bounces at lists.pushtotest.com]On Behalf Of Filipa Martins Soares Abrantes
Sent: Thursday, May 24, 2007 2:23 AM
To: fcohen at pushtotest.com  <mailto:fcohen at pushtotest.com> ; PushToTest TestMaker Developers List
Subject: [Dev] Test script with concurrent threads



  

 Hi!

I'm still trying to execute a test script with concurrent threads, but the threads are being executed in a sequential order instead. Can anyone tell me how can put the threads executing concurrently?

I really need some help!

This is the code I'm executing:

 

    numThread = 3
    numThreadPerBlocks = 5 
    fimThread = 0
    tinicio = Date().time 
    
    while (i < numThread):
        x = 0
        if (numThread - i < numThreadPerBlocks):
            numThreadPerBlocks = numThread - i
        
        while (x < numThreadPerBlocks): 
                print "Start thread ", i 
                test = Portal5( 1, 'console file ', 0, '20.|300|301|302|303|304|307|401|403|408|41.', ' log.xml', 5, 5, 5, 1, 1, 'Portal5', 1 ) 
                test.setUp()
                thread.start_new_thread( test.runTest(), (i,))
                x += 1
                i += 1  
                time.sleep(10)
                
        time.sleep (40)
        print "Stop between blocks" 
    
    while (fimThread < i):
        time.sleep(1)
 

This is my text output:

 

Start thread  0

Portal5: Initialize 

test: setUp

test: runTest

Request step: 1,  <http://www1.asd.pt/PortalWeb/content/> http://www1.asd.pt/PortalWeb/content/

Request step: 2,  <http://www1.asd.pt/PortalWeb/content/> http://www1.asd.pt/PortalWeb/content/

..

Start thread  1

Portal5: Initialize 

test: setUp

test: runTest

Request step: 1,  <http://www1.asd.pt/PortalWeb/content/> http://www1.asd.pt/PortalWeb/content/

Request step: 2,  <http://www1.asd.pt/PortalWeb/content/> http://www1.asd.pt/PortalWeb/content/

 

 

 

Thanks in advance, 

Filipa


_______________________________________________ 
Dev mailing list
Dev at lists.pushtotest.com
http://lists.pushtotest.com/mailman/listinfo/dev






-- 
Filipa M. Soares Abrantes 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cake.pushtotest.com/pipermail/dev/attachments/20070524/31b0381e/attachment-0001.htm


More information about the Dev mailing list