Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12682

Re: Why doesn't threading.join() return a value?

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Why doesn't threading.join() return a value?
Date 2011-09-02 19:16 -0400
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-030914.19162802092011@news.panix.com> (permalink)
References <61044fa5-2850-4f05-a55a-d61521c74313@d7g2000vbv.googlegroups.com> <5da6bf87-9412-46c4-ad32-f8337d56b2c3@o15g2000vbe.googlegroups.com>

Show all headers | View raw


In article 
<5da6bf87-9412-46c4-ad32-f8337d56b2c3@o15g2000vbe.googlegroups.com>,
 Adam Skutt <askutt@gmail.com> wrote:

> On Sep 2, 10:53 am, Roy Smith <r...@panix.com> wrote:
> > I have a function I want to run in a thread and return a value.  It
> > seems like the most obvious way to do this is to have my target
> > function return the value, the Thread object stash that someplace, and
> > return it as the return value for join().
> > > Yes, I know there's other ways for a thread to return values (pass the
> > target a queue, for example), but making the return value of the
> > target function available would have been the most convenient.  I'm
> > curious why threading wasn't implemented this way.
> 
> I assume it is because the underlying operating system APIs do not
> support it.  Windows and POSIX threads only support returning an
> integer when a thread exits, similar to the exit code of a process.

But the whole point of higher level languages is to hide the warts of 
the lower-level APIs they are built on top of.  Just because a POSIX 
thread can only return an int (actually, a void *) doesn't mean that 
level of detail needed to be exposed at the Python threading library 
level.

> More importantly, there's no way to tell whether the exit code of a
> thread was set by user code or by the system.  Even worse, some of
> those integer values are reserved by some operating systems.  If your
> thread died via an exception, it still has an error code set by the
> operating system.  How would you going to distinguish those codes from
> your own?

I think you're talking about processes, not threads, but in any case, 
it's a non-sequitur.  Thread.join() currently returns None, so there's 
no chance for confusion.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why doesn't threading.join() return a value? Roy Smith <roy@panix.com> - 2011-09-02 07:53 -0700
  Re: Why doesn't threading.join() return a value? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-03 01:45 +1000
    Re: Why doesn't threading.join() return a value? Seebs <usenet-nospam@seebs.net> - 2011-09-02 16:42 +0000
      Re: Why doesn't threading.join() return a value? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-09-03 06:49 +1000
  Re: Why doesn't threading.join() return a value? Adam Skutt <askutt@gmail.com> - 2011-09-02 11:01 -0700
    Re: Why doesn't threading.join() return a value? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-09-02 20:23 +0200
      Re: Why doesn't threading.join() return a value? Adam Skutt <askutt@gmail.com> - 2011-09-02 11:53 -0700
        Re: Why doesn't threading.join() return a value? Chris Torek <nospam@torek.net> - 2011-09-02 20:14 +0000
          Re: Why doesn't threading.join() return a value? Adam Skutt <askutt@gmail.com> - 2011-09-02 15:02 -0700
          Re: Why doesn't threading.join() return a value? Roy Smith <roy@panix.com> - 2011-09-03 12:51 -0400
        Re: Why doesn't threading.join() return a value? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-09-03 10:33 +0200
          Re: Why doesn't threading.join() return a value? Alain Ketterlin <alain@dpt-info.u-strasbg.fr> - 2011-09-03 11:00 +0200
        Re: Why doesn't threading.join() return a value? Carl Banks <pavlovevidence@gmail.com> - 2011-09-03 05:27 -0700
    Re: Why doesn't threading.join() return a value? Roy Smith <roy@panix.com> - 2011-09-02 19:16 -0400
      Re: Why doesn't threading.join() return a value? Chris Torek <nospam@torek.net> - 2011-09-03 01:04 +0000
    Re: Why doesn't threading.join() return a value? Carl Banks <pavlovevidence@gmail.com> - 2011-09-03 05:04 -0700

csiph-web