Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:26:26+00:00 2026-05-30T17:26:26+00:00

I’m having trouble developing a standard for returning data from user functions passed and

  • 0

I’m having trouble developing a standard for returning data from user functions passed and executed in a class which runs the function as a separate thread.

The goal would be to pass the return arguments from the function when requested for by the user.

But what if the function is not finished running when the user requests data from my class? Or if the function fails and hence has no data (but its failure is not critical to the program, meaning raising an exception is excessive)

I had thought to just return None but what if the user function returns None and that is meaningful (ie the function completed successfully)? My next idea was to return the function output in a list and None if no data was ready or available. This would mean the user would have to check if the data was returned or not (check if None or a list) which I find slightly inelegant.

I am curious if there is already a standard for things like this or if anyone has a suggestion that is cleaner.

example:

user call

def foo():
    #...do lots of stuff that takes long time

    # return whether stuff worked or not (None if worked False if not)
    return success 

takes_forever = detach(foo)

# ... do other things

# get data from detached function which has hopefully completed
are_you_done = takes_forever.give_me_data()

My class:

class detach:
    def __init__(self, func):
        self.detached_func = execute_as_thread(func)

    def give_me_data(self) 
        if self.detached_func.is_done():        # function completed and didnt die
            return [self.detached_func.output]
        else:                                   # something went wrong or function is still running
            return None
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:26:27+00:00Added an answer on May 30, 2026 at 5:26 pm

    Best would be to raise exception, if for some reason you want to avoid that return a sepecial object e.g. define a class NoResultsType and return object of such type or may be just the class

    class NoResultsType(object): pass
    
    NoResults = NoResultsType()
    
    def give_me_data(self) 
        if self.detached_func.is_done():        # function completed and didnt die
            return [self.detached_func.output]
        else:                                   # something went wrong or function is still running
            return NoResults
    

    and then you can define multiple such types e.g. NoResults, FunctionFailed etc and user can just check them e.g.

    ret = foo.give_me_data()
    if ret in [NoResultsYet, FunctionFailed]:
       # do something
    

    or you can return a Result object which can keep original result, states etc

    class Result(object):
        def __init__(self):
             self.finished = False
             self.success = False
             self.error = ""
             self.result = None
    
    res = foo.give_me_data()
    if res.success:
        print res.result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am currently running into a problem where an element is coming back from
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.