librelist archives

« back to archive

http request without waiting for a response

http request without waiting for a response

From:
Norbert Markowicz
Date:
2013-05-19 @ 14:26
Hi guys,

I'm still learning about http requests, but what is the best way to send a
request from the client side without expecting a response in return, and
instead just have the server execute a command.

For example, can I send a get request from the client side and not have the
connection wait for the server to finish executing the command a sending a
response?

or do I need to send a POST request?

Thanks

Re: [flask] http request without waiting for a response

From:
Raj Nathani
Date:
2013-05-19 @ 14:39
One way to go about it would be to respond to the server immediately (with
a blank response) and before sending the response kicking off a background
process to complete the job to be done.

And about sending a POST request, that doesn't matter here.

Sent from my iPhone

On 2013-05-19, at 10:28 AM, "Norbert Markowicz" 
<norbert.markowicz@gmail.com> wrote:

> Hi guys,
> 
> I'm still learning about http requests, but what is the best way to send
a request from the client side without expecting a response in return, and
instead just have the server execute a command.
> 
> For example, can I send a get request from the client side and not have 
the connection wait for the server to finish executing the command a 
sending a response?
> 
> or do I need to send a POST request?
> 
> Thanks

Re: [flask] http request without waiting for a response

From:
Muhammad Hallaj Subery
Date:
2013-05-19 @ 14:40
Hi

    Based on my understanding of your question, you want to archive the
following:

    1. Trigger a URL to a remote server to perform a task
    2. Close the connection to the server without waiting for it to
complete.

    If that's the case, I can think of two ways of getting it.

    1. If the remote task can be performed multiple time without issues,
simply put the targeted task in the background on the server side.
    2. If you're expecting a lot of requests on the server side and that
each task should perform one at a time, try looking into Queue systems.
There's a few worth mentioning here (msgpack, zeromq) - There's also a
flask snippet on message queue on redis -
http://flask.pocoo.org/snippets/73/

    I hope that would help.


On Sun, May 19, 2013 at 10:26 PM, Norbert Markowicz <
norbert.markowicz@gmail.com> wrote:

> Hi guys,
>
> I'm still learning about http requests, but what is the best way to send a
> request from the client side without expecting a response in return, and
> instead just have the server execute a command.
>
> For example, can I send a get request from the client side and not have
> the connection wait for the server to finish executing the command a
> sending a response?
>
> or do I need to send a POST request?
>
> Thanks
>

Re: [flask] http request without waiting for a response

From:
Norbert Markowicz
Date:
2013-05-19 @ 21:07
Thanks for the help so far guys. My question is then around how to trigger
a background task with the flask routing and then immediately go to the
next step in the route function.
In my draft example below, the _search request triggers the new thread to
be spawned and the thread start executing, but the request does
not immediately go on to the next step in the function - print "Onto the
next already" - until the thread has completed.

def consumer(searchValue,assignedUniqueID):

        resultsarray = []****

        regx.append(re.compile(searchValue,re.IGNORECASE))****

        print "Searching..."****

        print "Running thread! Args:", (searchValue, assignedUniqueID)****

        time.sleep(10)****

        print "Done!"****


@app.route('/_search')

def add_numbers():****

    global assignedUniqueID****

    global searchValue****

    searchValue = request.args.get('a', type=str)****

    print searchValue****

    assignedUniqueID = str(uuid.uuid4())****

    Thread(target=consumer(searchValue,assignedUniqueID)).start()****

    **def consumer(searchValue,assignedUniqueID):

        global i****

        global insightdatacollection****

        global resultsarray****

        resultsarray = []****

        regx.append(re.compile(searchValue,re.IGNORECASE))****

        print "Searching..."****

        print "Running thread! Args:", (searchValue, assignedUniqueID)****

        time.sleep(10)****

        print "Done!"****


@app.route('/_search')****

def add_numbers():****

    global assignedUniqueID****

    global searchValue****

    searchValue = request.args.get('a', type=str)****

    print searchValue****

    assignedUniqueID = str(uuid.uuid4())****

*    Thread(target=consumer(searchValue,assignedUniqueID)).start()*

*    print "Onto the next already"*****

    return jsonify(result="33434443",****

                           assignedUniqueID = assignedUniqueID****

                   )

    return jsonify(result="33434443",****

                           assignedUniqueID = assignedUniqueID****

                   )


On Sun, May 19, 2013 at 10:40 AM, Muhammad Hallaj Subery
<hallajs@gmail.com>wrote:

> Hi
>
>     Based on my understanding of your question, you want to archive the
> following:
>
>     1. Trigger a URL to a remote server to perform a task
>     2. Close the connection to the server without waiting for it to
> complete.
>
>     If that's the case, I can think of two ways of getting it.
>
>     1. If the remote task can be performed multiple time without issues,
> simply put the targeted task in the background on the server side.
>     2. If you're expecting a lot of requests on the server side and that
> each task should perform one at a time, try looking into Queue systems.
> There's a few worth mentioning here (msgpack, zeromq) - There's also a
> flask snippet on message queue on redis -
> http://flask.pocoo.org/snippets/73/
>
>     I hope that would help.
>
>
>  On Sun, May 19, 2013 at 10:26 PM, Norbert Markowicz <
> norbert.markowicz@gmail.com> wrote:
>
>> Hi guys,
>>
>> I'm still learning about http requests, but what is the best way to send
>> a request from the client side without expecting a response in return, and
>> instead just have the server execute a command.
>>
>> For example, can I send a get request from the client side and not have
>> the connection wait for the server to finish executing the command a
>> sending a response?
>>
>> or do I need to send a POST request?
>>
>> Thanks
>>
>
>