Forums

[RFC] Change how consoles behave with API interaction

A Request to the PythonAnywhere team.

Is there a good technical reason why an existing console can't auto restart when we do an API interaction ?

I have two consoles on my account (one for each webapp), and i am using the API to interact with them, having first opened them through the browsers.

After 24 hours or so of no interaction the consoles seem to time out (I get that this might be neccessary - in order to save resources, no point having processes being idle on the server), but after this timeout, any further interaction with those consoles vie the API results in an error:

code: 412 text: Console not yet started. Please load it (or its iframe) in a browser first

Is there any way of having consoles be auto-revived by an API interaction ? Could a flag be kept on each console once it is opened by the browser, such that a new API request on that console, restarts the process if it is down.

NOTE : I am not asking for a 'POST' to /api/v0/user/{username}/consoles/ to create a new process - I understand why that might be restricted. I am talking about an API interaction on an existing console which has already been opened via the browser.

Thanks for the suggestion! That's something we've intended to add for some time, so it's on our backlog -- I'll add an upvote on your behalf to pull it up the list a bit.

Thank you - is there any indication of when it might hit the release sprint ?

No, we do not have an estimate on when we will do it.

@glenn - thank you. it is an important feature for me for my new desktop tool - having a desk top tool that removes the need for you to log in to the site is a bit negated by the need to login once a day.

What is the time out length, and as a matter of interest does a command sent via the API keep the process alive (ie could the occassional 'pwd' command top the console process closing ?

There's no strict timeout -- instead, we restart console servers when they need to be restarted, so that tends to follow an "every few days" kind of candence.

@giles and glen - thank you so much for your answers. They have been enlightening.

As a matter of interest have you seen my other post : https://eu.pythonanywhere.com/forums/topic/486/ announcing the start of development for my desktop tool. I am close to having release 0.1 available (probably just on github for now) : ie i have a GUI, basic config and the GUI contains a terminal into which you can type commands and see responses.

That's great! What OS is the desktop tool for?

Initial development will be under Linux (versions 0.1 through to 0.5 or so), but I do plan to test windows compatibility as well before full release. If i can get one or more contributors that will be easier to do. I don't have a Mac (or a Mac O/S image) so I can't do anything about Mac on my own. The code will be Python (with PySide6 for the GUI), so it should be compatible across platform.

BTW @giles : Is there a test harness for the API - it would be good to be able to drive automated testing against a mocked API, rather than trying to replicate the API in a test harness, or do automated testing against my production and 'LiveTesting' instances

Unfortunately we don't have a test harness for the API, no :-(

We might be able to help out with some testing on Macs, though!

Thanks for the details regarding the API testing - I will have a think about how to proceed.

Thanks also for the offerr of MAC testing - I am a bit away from that currently, but I will be in touch when i am closer.

Great! Just let us know.

@giles - would it be possible that you could DM me vie email ?

@BranthamGarageSale could you drop us a line at support@pythonanywhere.com with a link to this thread?