How do start a flask app and stop it from IDE

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How do start a flask app and stop it from IDE

WingIDE - User mailing list
Hi,

I am writing a very small flask app and using this IDE. For now, I have to go out of the editor to start the app and stop it from my system terminal. Is there any way I can set configure so that I don’t need to leave the editor.


Thanks,

Arup Rakshit
[hidden email]



_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
Arup Rakshit via wingide-users wrote:
> I am writing a very small flask app and using this IDE. For now, I have to go out of the editor to start the app and stop it from my system terminal. Is there any way I can set configure so that I don’t need to leave the editor.

You can set it up to start and stop Flask from Wing.  For that to work
well, you need to turn off Flask's built-in debugger, so Wing's debugger
can take over reporting exceptions.  Actually you may already be doing
that even if starting on the command line, if you are debugging it with
wingdbstub.

This is described in more detail in http://wingware.com/doc/howtos/flask 
under Debugging Flask in Wing.  That also has information on setting up
Flask to auto-reload changes so you don't need to restart it to try out
code as you write it in Wing.

Please let me know if you run into problems with any of this.

Thanks,

Stephan Deibel
Wing Python IDE | The Intelligent Development Environment for Python



_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
I went through this page. I have not seen how to stop the server after I ran it. I had to use `ps` and `kill` command to kill it. :) How do you I the server ?


Thanks,

Arup Rakshit
[hidden email]



> On 04-May-2019, at 12:31 AM, Wingware Support <[hidden email]> wrote:
>
> Arup Rakshit via wingide-users wrote:
>> I am writing a very small flask app and using this IDE. For now, I have to go out of the editor to start the app and stop it from my system terminal. Is there any way I can set configure so that I don’t need to leave the editor.
>
> You can set it up to start and stop Flask from Wing.  For that to work well, you need to turn off Flask's built-in debugger, so Wing's debugger can take over reporting exceptions.  Actually you may already be doing that even if starting on the command line, if you are debugging it with wingdbstub.
>
> This is described in more detail in http://wingware.com/doc/howtos/flask under Debugging Flask in Wing.  That also has information on setting up Flask to auto-reload changes so you don't need to restart it to try out code as you write it in Wing.
>
> Please let me know if you run into problems with any of this.
>
> Thanks,
>
> Stephan Deibel
> Wing Python IDE | The Intelligent Development Environment for Python
>
>
>

_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
Arup Rakshit via wingide-users wrote:
I went through this page. I have not seen how to stop the server after I ran it. I had to use `ps` and `kill` command to kill it. :) How do you I the server ?

Once you set your main entry point and start debugging Flask in Wing you can kill it with the red stop icon in the toolbar or Stop Debugging item in the Debug menu.  Also, the restart icon in the toolbar is a quick way to stop and restart Flask.


Stephan Deibel
Wing Python IDE | The Intelligent Development Environment for Python




_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
Hm,

This is my small python app.

from flask import Flask, jsonify

app = Flask(__name__)

books = [
    {
        "name": 'Learning Python',
        'isbn': '1449355730',
        'price': 200
    },
    {
        "name": 'Practical Object-Oriented Design: An Agile Primer Using Ruby',
        'isbn': 'B07F88LY9M',
        'price': 210
    }
]


@app.route("/books")
def get_books():
    return jsonify({'books': books})


@app.route('/books/<isbn>')
def get_book_by_isbn(isbn):
    return jsonify([{'name': book['name'], 'price': book['price']} for book in books if book['isbn'] == isbn])


if __name__ == "__main__":
    import os
    if 'WINGDB_ACTIVE' in os.environ:
        app.debug = False
    app.run(use_reloader=True)



I can start it by clicking on “Debug Current File”, but when I click the stop button, it says debug session ended. But I see the app is still running.


Thanks,

Arup Rakshit
[hidden email]



> On 04-May-2019, at 12:39 AM, Wingware Support <[hidden email]> wrote:
>
> Arup Rakshit via wingide-users wrote:
>> I went through this page. I have not seen how to stop the server after I ran it. I had to use `ps` and `kill` command to kill it. :)
>>  How do you I the server ?
>>
>
> Once you set your main entry point and start debugging Flask in Wing you can kill it with the red stop icon in the toolbar or Stop Debugging item in the Debug menu.  Also, the restart icon in the toolbar is a quick way to stop and restart Flask.
>
>
> Stephan Deibel
> Wing Python IDE | The Intelligent Development Environment for Python
>
>
>

_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
Hi Luna,

I did it already. The server starts, but it never stops the server when I click on **Stop** button.


Thanks,

Arup Rakshit
[hidden email]



> On 05-May-2019, at 1:43 AM, Luna Tuna <[hidden email]> wrote:
>
> Go to the Projects  panel, right click on your [main.py]  file, select Set As Main Debug File.  Hit  play now.
>
> On Sat, May 4, 2019 at 1:01 PM Arup Rakshit via wingide-users <[hidden email]> wrote:
>

_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
Luna,


Hm. Probably something is missing here. I don’t know why..


Thanks,

Arup Rakshit
[hidden email]



> On 05-May-2019, at 3:35 AM, Luna Tuna <[hidden email]> wrote:
>
> lol  😂 it's borked for you
>
> On Sat, May 4, 2019 at 2:52 PM Arup Rakshit via wingide-users <[hidden email]> wrote:
> Hi Luna,
>
> I did it already. The server starts, but it never stops the server when I click on **Stop** button.
>
>
> Thanks,
>
> Arup Rakshit
> [hidden email]
>
>
>
> > On 05-May-2019, at 1:43 AM, Luna Tuna <[hidden email]> wrote:
> >
> > Go to the Projects  panel, right click on your [main.py]  file, select Set As Main Debug File.  Hit  play now.
> >
> > On Sat, May 4, 2019 at 1:01 PM Arup Rakshit via wingide-users <[hidden email]> wrote:
> >
>
> _________________________________________________
> Wing Python IDE users list
> http://wingware.com/lists/wingide

_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
In reply to this post by WingIDE - User mailing list
Arup Rakshit via wingide-users wrote:
I can start it by clicking on “Debug Current File”, but when I click the stop button, it says debug session ended. But I see the app is still running.

Do you also have Debug Child Processes enabled, under the Debug/Execute tab in Project Properties from the Project menu?

If so, can you let us know what OS you're on, what version of Wing you have, and what version of Flask it is so we can try it here?

Thanks,

--

Stephan Deibel
Wing Python IDE | The Intelligent Development Environment for Python




_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
In reply to this post by WingIDE - User mailing list
Arup Rakshit via wingide-users wrote:
if __name__ == "__main__":
    import os
    if 'WINGDB_ACTIVE' in os.environ:
        app.debug = False
    app.run(use_reloader=True)



I can start it by clicking on “Debug Current File”, but when I click the stop button, it says debug session ended. But I see the app is still running.

I was able to replicate this reliably 5-10 times but now it's working again.  At first in my test I had forgotten to set Project > Project Properties > Debug Child Processes to Always Debug Child Processes and thought that might be it.  It *does* need to be set, but that alone didn't solve it for me.

So then I tried some variants on the run() call:

* I tried running with app.run(use_reloader=False) -- this fixed it, and I think can be used as a work-around in any case since I'm fairly sure it's the child process that was not terminated

* I tried running with app.run(use_reloader=True, debug=False) -- this also worked for me but I suspect it's not a real solution.

I'm back to app.run(use_reloader=True) and it works reliably for me now. I think this probably just mean it's a timing issue, in terms of how we kill the processes.  The Flask parent may end up relaunching the child after we kill it, in a way that we end up missing.  But I can't replicate it now, despite many attempts, so I'm not 100% sure that's it.

I was testing this on OS X with Flask 0.12.2 and Wing 7.0.1.2.  It would still be useful to know at least what OS you are on, since process control is entirely different on Windows.

Thanks,

Stephan Deibel
Wing Python IDE | The Intelligent Development Environment for Python



_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list

On 06-May-2019, at 6:26 PM, Wingware Support <[hidden email]> wrote:

Arup Rakshit via wingide-users wrote:
if __name__ == "__main__":
    import os
    if 'WINGDB_ACTIVE' in os.environ:
        app.debug = False
    app.run(use_reloader=True)



I can start it by clicking on “Debug Current File”, but when I click the stop button, it says debug session ended. But I see the app is still running.


I was able to replicate this reliably 5-10 times but now it's working again.  At first in my test I had forgotten to set Project > Project Properties > Debug Child Processes to Always Debug Child Processes and thought that might be it.  It *does* need to be set, but that alone didn't solve it for me.


This settings did the job for me.

So then I tried some variants on the run() call:

* I tried running with app.run(use_reloader=False) -- this fixed it, and I think can be used as a work-around in any case since I'm fairly sure it's the child process that was not terminated

* I tried running with app.run(use_reloader=True, debug=False) -- this also worked for me but I suspect it's not a real solution.

I'm back to app.run(use_reloader=True) and it works reliably for me now. I think this probably just mean it's a timing issue, in terms of how we kill the processes.  The Flask parent may end up relaunching the child after we kill it, in a way that we end up missing.  But I can't replicate it now, despite many attempts, so I'm not 100% sure that's it.

I was testing this on OS X with Flask 0.12.2 and Wing 7.0.1.2.  It would still be useful to know at least what OS you are on, since process control is entirely different on Windows.

Here is the screenshot attached.



Thanks,

Stephan Deibel
Wing Python IDE | The Intelligent Development Environment for Python



It is working now. Thanks for your help.


Thanks,

Arup Rakshit
[hidden email]

_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
In reply to this post by WingIDE - User mailing list
Hi,

I think it will be good if this is mentioned in the user guide too.


Thanks,

Arup Rakshit
[hidden email]



> On 06-May-2019, at 6:26 PM, Wingware Support <[hidden email]> wrote:
>
> Arup Rakshit via wingide-users wrote:
>> if __name__ == "__main__":
>>     import os
>>     if 'WINGDB_ACTIVE' in os.environ:
>>         app.debug = False
>>     app.run(use_reloader=True)
>>
>>
>>
>> I can start it by clicking on “Debug Current File”, but when I click the stop button, it says debug session ended. But I see the app is still running.
>>
>
> I was able to replicate this reliably 5-10 times but now it's working again.  At first in my test I had forgotten to set Project > Project Properties > Debug Child Processes to Always Debug Child Processes and thought that might be it.  It *does* need to be set, but that alone didn't solve it for me.
>
> So then I tried some variants on the run() call:
>
> * I tried running with app.run(use_reloader=False) -- this fixed it, and I think can be used as a work-around in any case since I'm fairly sure it's the child process that was not terminated
>
> * I tried running with app.run(use_reloader=True, debug=False) -- this also worked for me but I suspect it's not a real solution.
>
> I'm back to app.run(use_reloader=True) and it works reliably for me now. I think this probably just mean it's a timing issue, in terms of how we kill the processes.  The Flask parent may end up relaunching the child after we kill it, in a way that we end up missing.  But I can't replicate it now, despite many attempts, so I'm not 100% sure that's it.
>
> I was testing this on OS X with Flask 0.12.2 and Wing 7.0.1.2.  It would still be useful to know at least what OS you are on, since process control is entirely different on Windows.
>
> Thanks,
>
> Stephan Deibel
> Wing Python IDE | The Intelligent Development Environment for Python
>
>

_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide
Reply | Threaded
Open this post in threaded view
|

Re: How do start a flask app and stop it from IDE

WingIDE - User mailing list
Arup Rakshit wrote:
> I think it will be good if this is mentioned in the user guide too.

The need for Debug Child Processes is already in the Flask How-To in the
section "Setting up Auto-Reload with Wing Pro":

http://wingware.com/doc/howtos/flask

It is only relevant if you set use_reloader=True.

Stephan Deibel
Wing Python IDE | The Intelligent Development Environment for Python


_________________________________________________
Wing Python IDE users list
http://wingware.com/lists/wingide