Forums

Always-on tasks - Infinite Loop

Hi,

Sorry if my question sounds stupid but I was wondering if I can run a python script with infinite loop using pythonanywhere for a personnal project without burning my CPU time with a web dev account ?

The script basically request data from trading exchange public api, put them in a dataframe and store the dataframe into a postgresql database.

It is running well on my computer but I am looking some platform where I can deploy my python script + database in order to make it run 24/7.

Thanks

sure, you can run that in a loop, and use alwayson tasks to keep it up and running even in cases where your task occassionally errors out or the server is rebooted for maintenance etc

Hi Conrad,

Thanks for your reply.

What about the CPU time limitation ? I dont really know how much '4,000 CPU-seconds per day ' represents and if it will be enough to run my code 24/7. Do you know how can I calculate how much CPU-seconds does my code consume ?

You can use the time Bash command. It prints out the amount of CPU time used by a program; for example, if you consider this Python script:

import time

time.sleep(5)

start = time.time()
while time.time() - start < 3:
    pass

...it will sleep for 5 seconds, then spend about 3 seconds burning CPU in a busy wait. If you run it in Bash using the time command, you'll see something like this:

$ time python timer.py
real    0m8.131s
user    0m2.780s
sys     0m0.044s

...that is, it took 8.1 seconds to run and the total CPU time used was 2.780 + 0.044 seconds.