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
[Value Returning Threard]
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
  11 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
 
yoav glazner  
View profile  
 More options May 6 2009, 4:08 pm
From: yoav glazner <yoavglaz...@gmail.com>
Date: Wed, 6 May 2009 23:08:56 +0300
Local: Wed, May 6 2009 4:08 pm
Subject: [Python-ideas] [Value Returning Threard]

Hi all,
My Idea is to have a value returning Thread.
I'll explain by example.
<pycode>
def foo():
    time.sleep(20)
    return 'bar'

value = thread.startValueReturningThread(foo) #i need a better name for the
function...)

#here we do some work
mg = moonGravity()
mg.disable()

#now we need the value that foo returned
print value #this would be blocking untill foo is done!
</pycode>

This feature should provide a way to increase performance when possible with
simple syntax.

What do you think?

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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 Rebert  
View profile  
 More options May 6 2009, 4:41 pm
From: Chris Rebert <pyid...@rebertia.com>
Date: Wed, 6 May 2009 13:41:09 -0700
Local: Wed, May 6 2009 4:41 pm
Subject: Re: [Python-ideas] [Value Returning Threard]

Sounds like you haven't heard of Futures -
http://en.wikipedia.org/wiki/Future_(programming)
One of probably many recipes for them in Python:
http://code.activestate.com/recipes/84317/

Cheers,
Chris
--
http://blog.rebertia.com
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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.
George Sakkis  
View profile  
 More options May 6 2009, 4:49 pm
From: George Sakkis <george.sak...@gmail.com>
Date: Wed, 6 May 2009 16:49:45 -0400
Local: Wed, May 6 2009 4:49 pm
Subject: Re: [Python-ideas] [Value Returning Threard]

You're looking for the threadmethod decorator [1]. I'm not sure it's
robust and useful enough to be included in the standard library
though.

George

[1] http://code.activestate.com/recipes/440569/
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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.
MRAB  
View profile  
 More options May 6 2009, 4:51 pm
From: MRAB <goo...@mrabarnett.plus.com>
Date: Wed, 06 May 2009 21:51:47 +0100
Local: Wed, May 6 2009 4:51 pm
Subject: Re: [Python-ideas] [Value Returning Threard]

I think it would be better if startValueReturningThread() returned what
we could call a 'deferred result' object:

     result = thread.startValueReturningThread(foo)

If you requested the actual result before it was available then it would
wait:

     print result.value() # or 'result.value'?

It could be implemented using a thread and a queue.
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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.
Antoine Pitrou  
View profile  
 More options May 6 2009, 5:02 pm
From: Antoine Pitrou <solip...@pitrou.net>
Date: Wed, 6 May 2009 21:02:02 +0000 (UTC)
Local: Wed, May 6 2009 5:02 pm
Subject: Re: [Python-ideas] [Value Returning Threard]

MRAB <google@...> writes:

> I think it would be better if startValueReturningThread() returned what
> we could call a 'deferred result' object:

Or perhaps you just want to use Twisted.

Regards

Antoine.

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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.
Aahz  
View profile  
 More options May 6 2009, 5:02 pm
From: Aahz <a...@pythoncraft.com>
Date: Wed, 6 May 2009 14:02:21 -0700
Local: Wed, May 6 2009 5:02 pm
Subject: Re: [Python-ideas] [Value Returning Threard]

On Wed, May 06, 2009, yoav glazner wrote:

> #now we need the value that foo returned
> print value #this would be blocking untill foo is done!
> </pycode>

> This feature should provide a way to increase performance when possible with
> simple syntax.

Please provide more explanation for why the currently available features
are insufficient.  Note that what you're asking for would change the
semantics of Python at a very deep level and will almost certainly be
rejected in its present form.
--
Aahz (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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 Graham  
View profile  
 More options May 6 2009, 8:23 pm
From: John Graham <john.a.gra...@gmail.com>
Date: Wed, 6 May 2009 19:23:27 -0500
Local: Wed, May 6 2009 8:23 pm
Subject: Re: [Python-ideas] [Value Returning Threard]

If the OP is asking for futures, couldn't that be implemented in a
library without touching the language?  It's a powerful enough feature
to consider putting it in a library.  It's going to be one of the
'primitives' of C++0x if one wanted a precedent (although I'm not
suggesting everything C++ does is a good thing.  Or even most of what
C++ is a good thing).
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas

 
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.
yoav glazner  
View profile  
 More options May 7 2009, 2:10 am
From: yoav glazner <yoavglaz...@gmail.com>
Date: Thu, 7 May 2009 09:10:40 +0300
Local: Thurs, May 7 2009 2:10 am
Subject: Re: [Python-ideas] [Value Returning Threard]

> >Please provide more explanation for why the currently available features
> >are insufficient.  Note that what you're asking for would change the
> >semantics of Python at a very deep level and will almost certainly be
> >rejected in its present form.
> --
> >Aahz (a...@pythoncraft.com)           <*>
> http://www.pythoncraft.com/

I'm no python expert but i had to do a stress test on a libary. (checking
thread safety)
here is the code (we soe absraction):
def testMultiThread():
  global resultDict
  resultDict = {}
  def testFuncThread(func):
       global resultDict
       if func():
           resultDict[func] = 'Passed'
       else:
           resultDict[func] = 'Falied'
   thread.start_new(testFuncThread,(Test1,))
    thread.start_new(testFuncThread,(Test2,))
    thread.start_new(testFuncThread,(Test3,))

   while (len(resultDict) < 3):
         time.sleep(5)
   return resultDict #here i did something else such as logging and
returning True or False

Maybe there is a better way for doing this?
If we had something like i suggested (with .value or not)

 def testMultiThread():
    resultDict = {}

      resultDict[Test1]= thread.startValueReturningThread(Test1)
      resultDict[Test1]= thread.startValueReturningThread(Test2)
      resultDict[Test1]= thread.startValueReturningThread(Test3)

      return resultDict #or again, pharsing the result...

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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.
Antoine Pitrou  
View profile  
 More options May 7 2009, 2:31 am
From: Antoine Pitrou <solip...@pitrou.net>
Date: Thu, 7 May 2009 06:31:45 +0000 (UTC)
Local: Thurs, May 7 2009 2:31 am
Subject: Re: [Python-ideas] [Value Returning Threard]

John Graham <john.a.graham@...> writes:

> If the OP is asking for futures, couldn't that be implemented in a
> library without touching the language?  It's a powerful enough feature
> to consider putting it in a library.

I don't know what C++ futures are but you should take a look at Twisted Deferred
objects. The official implementation is in Python but a C implementation has
been lingering on for years, you may be able to give them some help:
http://twistedmatrix.com/trac/ticket/2245

Regards

Antoine.

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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.
Robert Collins  
View profile  
 More options May 7 2009, 2:43 am
From: Robert Collins <robe...@robertcollins.net>
Date: Thu, 07 May 2009 16:43:44 +1000
Local: Thurs, May 7 2009 2:43 am
Subject: Re: [Python-ideas] [Value Returning Threard]

On Thu, 2009-05-07 at 06:31 +0000, Antoine Pitrou wrote:
> John Graham <john.a.graham@...> writes:

> > If the OP is asking for futures, couldn't that be implemented in a
> > library without touching the language?  It's a powerful enough feature
> > to consider putting it in a library.

> I don't know what C++ futures are but you should take a look at Twisted Deferred
> objects. The official implementation is in Python but a C implementation has
> been lingering on for years, you may be able to give them some help:
> http://twistedmatrix.com/trac/ticket/2245

Futures block, Defereds call forward.

foo = something_returning_a_future() # does not block
foo.get_value() # blocks

def something_returning_a_future():
    def worker():
        [some code here that will does expensive work]
    return Future(worker)

class Future:
    def __init__(callable):
        # imagine thread-safe code here to run callable in a thread

    def get_value(self):
        if not self.result:
            self.result = self.queue.pop()
        return self.result

This is approximately a Future implementation for python. The difference
- and its quite a big one - to Defereds is that defereds are a
call-forward approach, whereas Futures are proxy objects that are waited
on to get their results.

twisted depends on never blocking as a core part of the design, Futures
and Promises don't work well here.

-Rob

  signature.asc
< 1K Download

_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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.
Aahz  
View profile  
 More options May 7 2009, 8:16 am
From: Aahz <a...@pythoncraft.com>
Date: Thu, 7 May 2009 05:16:01 -0700
Local: Thurs, May 7 2009 8:16 am
Subject: Re: [Python-ideas] [Value Returning Threard]

On Thu, May 07, 2009, yoav glazner wrote:

> I'm no python expert but i had to do a stress test on a libary.
>  [...]
> Maybe there is a better way for doing this?

For questions about using Python, please post to comp.lang.python
--
Aahz (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas


 
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 »