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

  • Home
  • SEARCH
  • 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 6320187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:55:40+00:00 2026-05-24T15:55:40+00:00

I wish to run a long-running script in the background upon receiving a request.

  • 0

I wish to run a long-running script in the background upon receiving a request. I read about subprocess but I require that the call is nonblocking so that the request can complete in time.

def controlCrawlers(request):

    if request.method == 'POST' and 'type' in request.POST and 'cc' in request.POST:

        if request.POST['type'] == '3':
            if request.POST['cc'] == '1':
                    try: #temp solution checking socket is occupied by trying to connect
                        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                        s.connect(('localhost',DISCOVERY_SOCKET))
                        s.close()

                        return HttpResponse(simplejson.dumps({'success':0,'message': 'Socket is occupied. Possible crawler is already running'}), \
                                        mimetype='application/json')
                    except:
                        pid = os.fork()

                        if pid == 0:
                            #f = open('/home/foo/django','a')
                            #f.write('abc')
                           # f.close()
                            path = os.path.join(os.path.dirname(__file__), 'blogcontentReader/blogpost_crawler.py')
                            os.system("python %s" %path)
                            os._exit(0)

                        return HttpResponse(simplejson.dumps({'success':1,'message': 'Running...'}), \
                                    mimetype='application/json')

I used os.fork as suggested from another post but apparently control does not flow into my if pid == 0 portion. Is this the correct method to do this?

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

    Yeah, don’t do this, use celery instead. It makes running asynchronous tasks a lot easier, more reliable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to build a Windows application that will generally run in the background,
I wish to write a shell script that calls a sql procedure(ultimately run the
Im having a little trouble with running a php script in the background. I
I have a piece of text, that I wish to show truncated, but when
I wish to run a powerbuilder application but I cannot find the runtime environment
I wish to run Eclipse for C++ on Vista but I absolutely do not
I wish to use an external Text/CSV file to read data and run an
I have a c# app that I am working on and wish to run
I run MAC OS X. So I have completed a python script that essentially
I wish to run a second instance of Hadoop on a machine which already

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.