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 6120221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:38:37+00:00 2026-05-23T15:38:37+00:00

In my django piston API, I want to yield/return a http response to the

  • 0

In my django piston API, I want to yield/return a http response to the the client before calling another function that will take quite some time. How do I make the yield give a HTTP response containing the desired JSON and not a string relating to the creation of a generator object?

My piston handler method looks like so:

def create(self, request):
    data = request.data 

    *other operations......................*

    incident.save()
    response = rc.CREATED
    response.content = {"id":str(incident.id)}
    yield response
    manage_incident(incident)

Instead of the response I want, like:

   {"id":"13"}

The client gets a string like this:

 "<generator object create at 0x102c50050>"

EDIT:

I realise that using yield was the wrong way to go about this, in essence what I am trying to achieve is that the client receives a response right away before the server moves onto the time costly function of manage_incident()

  • 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-23T15:38:38+00:00Added an answer on May 23, 2026 at 3:38 pm

    This doesn’t have anything to do with generators or yielding, but I’ve used the following code and decorator to have things run in the background while returning the client an HTTP response immediately.

    Usage:

    @postpone
    def long_process():
        do things...
    
    def some_view(request):
        long_process()
        return HttpResponse(...)
    

    And here’s the code to make it work:

    import atexit
    import Queue
    import threading
    
    from django.core.mail import mail_admins
    
    
    def _worker():
        while True:
            func, args, kwargs = _queue.get()
            try:
                func(*args, **kwargs)
            except:
                import traceback
                details = traceback.format_exc()
                mail_admins('Background process exception', details)
            finally:
                _queue.task_done()  # so we can join at exit
    
    def postpone(func):
        def decorator(*args, **kwargs):
            _queue.put((func, args, kwargs))
        return decorator
    
    _queue = Queue.Queue()
    _thread = threading.Thread(target=_worker)
    _thread.daemon = True
    _thread.start()
    
    def _cleanup():
        _queue.join()   # so we don't exit too soon
    
    atexit.register(_cleanup)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with django-piston to attempt to create an API that supports oAuth. I
Django view points to a function, which can be a problem if you want
I'm using django-piston for my REST json api, and I have it all set
I have a simple Django-Piston Handler that creates a new instance of a model
django-piston appears to create a data attribute on the request object before it gets
I've built a web service using Django-Piston that allows for POST and GET requests.
I've noticed that there are about 30 forks of Django Piston on GitHub: https://github.com/search?q=django-piston&type=Everything&repo=&langOverride=&start_value=1
I have a problems with my django api. I have a website that works
I am currently writing an API for a django project, and using django-piston for
Django has a number of open source projects that tackle one of the framework's

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.