Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Multi-thread testing
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John Lee  
View profile  
 More options Aug 30 2012, 2:32 am
From: John Lee <j...@0xlab.org>
Date: Wed, 29 Aug 2012 23:32:24 -0700 (PDT)
Local: Thurs, Aug 30 2012 2:32 am
Subject: Multi-thread testing

Dear all,

I was trying to debug a multi-thead issue. In order to reproduce it, I
wrote a multi-thread testing in tests.py, but got exception in
get_renderer('xxxx.pt'). After some digging, it turns out get_renderer will
eventually call get_current_registry, which is thread local.  So, I came
out with this hack:

<pre>
import pyramid.threadlocal
from threading import Thread, Lock

candidates = [
    (self._test1, ()),
    (self._test2, ()),
    (self._test3, ()),
    ]

def random_func(pyramid_thread_locals):
    pyramid.threadlocal.manager.push(pyramid_thread_locals)
    time.sleep(random.random())  # 0 ~ 1 sec
    func, args = random.choice(candidates)
    func(*args)

pyramid_thread_locals = pyramid.threadlocal.manager.get()
threads = [Thread(target=random_func, args=(pyramid_thread_locals, ),)
           for i in range(100)]
for thread in threads:
    thread.start()
for thread in threads:
    thread.join()
</pre>

There is no guarantee that pyramid.threadlocal.manager will always be
there. Even if it's there, there's no guarantee it can be used this way.
So, this should only be considered as a temporary workaround.

Question: is there a better way to do this?

Regards,
John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris McDonough  
View profile  
 More options Aug 30 2012, 4:42 am
From: Chris McDonough <chr...@plope.com>
Date: Thu, 30 Aug 2012 04:42:43 -0400
Local: Thurs, Aug 30 2012 4:42 am
Subject: Re: Multi-thread testing
On 08/30/2012 02:32 AM, John Lee wrote:

Is there a better way to do what?  What problem are you trying to solve?
  Is the above code a bug report?

- C


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Lee  
View profile  
 More options Aug 30 2012, 5:53 am
From: John Lee <j...@0xlab.org>
Date: Thu, 30 Aug 2012 17:53:17 +0800
Local: Thurs, Aug 30 2012 5:53 am
Subject: Re: Multi-thread testing
Hi,

No, it's not a bug report. It's a workaround to a problem I
encountered, and I was asking if there's is a better solution.

Like I said, the problem is that if someone write multi-thread testing
without the pyramid.threadlocal.manager hack I showed in the code
above, the newly created thread will have issues when it calls
get_current_registry, because request and registry are thread local.

BTW, each unit test (self._test1 ~ 3) should create its own request
and context (in case of traversal) to avoid racing conditions.

- John


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »