Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
- Dagriffpatchfan
-
1000+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
With crontab, how long does the script run? If I have a forever loop will it run for at least one minute? Every time it is automatically run?I have no clue what justablock or linl is and considering it's a dead website it was either defaced or just… dead. If you have RAM to spare I'd suggest just using shell, terminal, or whatever your computer uses to run a python file with your code in it (and put everything in a “while True:” loop if you don't plan on using something like Crontab, which runs scripts automatically at the specified intervals (limited though as smallest interval is 1 min)). That is the free option. Of course you can use something like replit but replit is now paid for so… yeah. I tried setting up a scratchattach server with justablock the linled free server but clicking the verify linl leads to a dead website… whats going on
I thoughtaybe it was the safety restrictions on my internet but using a proxy didnt help
- MonkeyBean2
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
Restarting it every minute or something is not a good idea, since you will be reconnecting to the cloud server every time which is not good. Plus if you don't kill it after one minute it will create multiple connections which will create conflicts. If crontab doesn't run it if it's still running then this would be fine though, and it would only restart it when necessary.I have no clue what justablock or linl is and considering it's a dead website it was either defaced or just… dead. If you have RAM to spare I'd suggest just using shell, terminal, or whatever your computer uses to run a python file with your code in it (and put everything in a “while True:” loop if you don't plan on using something like Crontab, which runs scripts automatically at the specified intervals (limited though as smallest interval is 1 min)). That is the free option. Of course you can use something like replit but replit is now paid for so… yeah. I tried setting up a scratchattach server with justablock the linled free server but clicking the verify linl leads to a dead website… whats going on
I thoughtaybe it was the safety restrictions on my internet but using a proxy didnt help
Instead of using crontab, you can just make sure your script won't exit, or write another script to restart it if it does exit (you can use shell/bash for this), and then just leave your script running. If you want it to run in the background, you can use this command:
screen -dmS <name> <command>
screen -dmS scratchserver0 python3 main.py
screen -r <name>
screen -ls
Last edited by MonkeyBean2 (Nov. 29, 2024 17:38:11)
- MonkeyBean2
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
A better way is to use a CSV like format, so you can just append to the file instead of reading and writing all of it at once. This also reduces the load on your disk which is good if you are using a raspberry pi with a microsd card. You can just have the project id, timestamp and then all of the stats in the CSV. You could even just put JSON in there (make sure it doesn't have newlines though), but it's probably better to make each value a separate CSV parameter, as that makes it much easier to process it (you can use most spreadsheet software). Also once a day sounds a bit slow lol. I am trying to make a project that monitors a scratch project so it can record the stats of it (views loves favs remixes) however I have not been able to think of a way to do this efficiently. The project would collect data once per day and save it to some type of file (im thinking with JSON but idk if that's a good choice). Here is what I thought of.
So you have a dictionary that has all the project ids of different projects the code is monitoring as keys, inside of each key in that dictionary you have another dictionary that has every day that it was collecting data. In each of thoughs keys you have a list with 4 items in it: views loves favorites and remixes.
While I think this would maybe work I also think it would take up a lot more power then is needed to make small additions to the data especially if it is getting the stats of a lot of projects at the same time.
Thanks!
- Dagriffpatchfan
-
1000+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
1. Is this instructions for a windows pc?Restarting it every minute or something is not a good idea, since you will be reconnecting to the cloud server every time which is not good. Plus if you don't kill it after one minute it will create multiple connections which will create conflicts. If crontab doesn't run it if it's still running then this would be fine though, and it would only restart it when necessary.I have no clue what justablock or linl is and considering it's a dead website it was either defaced or just… dead. If you have RAM to spare I'd suggest just using shell, terminal, or whatever your computer uses to run a python file with your code in it (and put everything in a “while True:” loop if you don't plan on using something like Crontab, which runs scripts automatically at the specified intervals (limited though as smallest interval is 1 min)). That is the free option. Of course you can use something like replit but replit is now paid for so… yeah. I tried setting up a scratchattach server with justablock the linled free server but clicking the verify linl leads to a dead website… whats going on
I thoughtaybe it was the safety restrictions on my internet but using a proxy didnt help
Instead of using crontab, you can just make sure your script won't exit, or write another script to restart it if it does exit (you can use shell/bash for this), and then just leave your script running. If you want it to run in the background, you can use this command:eg.screen -dmS <name> <command>and then to exit it or view its output you can doscreen -dmS scratchserver0 python3 main.pyand if you forgot the name you used you can usescreen -r <name>to list all running screen sessions. Once you have gotten back into it with screen -r you can do ctrl+d to stop it.screen -ls
2. I dont have admin priveleges and sign out of my account when Im done using the computer because I dont have a ton of screen time…does this still work when signed out?
- davidtheplatform
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
1. The instructions are for a Linux computer. It also works on WSL.1. Is this instructions for a windows pc?Restarting it every minute or something is not a good idea, since you will be reconnecting to the cloud server every time which is not good. Plus if you don't kill it after one minute it will create multiple connections which will create conflicts. If crontab doesn't run it if it's still running then this would be fine though, and it would only restart it when necessary.I have no clue what justablock or linl is and considering it's a dead website it was either defaced or just… dead. If you have RAM to spare I'd suggest just using shell, terminal, or whatever your computer uses to run a python file with your code in it (and put everything in a “while True:” loop if you don't plan on using something like Crontab, which runs scripts automatically at the specified intervals (limited though as smallest interval is 1 min)). That is the free option. Of course you can use something like replit but replit is now paid for so… yeah. I tried setting up a scratchattach server with justablock the linled free server but clicking the verify linl leads to a dead website… whats going on
I thoughtaybe it was the safety restrictions on my internet but using a proxy didnt help
Instead of using crontab, you can just make sure your script won't exit, or write another script to restart it if it does exit (you can use shell/bash for this), and then just leave your script running. If you want it to run in the background, you can use this command:eg.screen -dmS <name> <command>and then to exit it or view its output you can doscreen -dmS scratchserver0 python3 main.pyand if you forgot the name you used you can usescreen -r <name>to list all running screen sessions. Once you have gotten back into it with screen -r you can do ctrl+d to stop it.screen -ls
2. I dont have admin priveleges and sign out of my account when Im done using the computer because I dont have a ton of screen time…does this still work when signed out?
2. You shouldn’t use your normal computer for this. Do you have a raspberry pi which can stay on 24/7?
If you have to use windows, you can use task scheduler to run something every minute (or any period of time). I haven’t used it before though so I can’t give instructions.
- Dagriffpatchfan
-
1000+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
1. I have a raspberry pi.
2.I have tried to use task scheduoer but Im not the admin of my pc and it never works like it should…
I am actually good now - I finally figured out how to run code on my pi!
2.I have tried to use task scheduoer but Im not the admin of my pc and it never works like it should…
I am actually good now - I finally figured out how to run code on my pi!
- MonkeyBean2
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
if using your pi, use the method I showed you with screen, that way if you are using ssh you can close the session and it will keep running 1. I have a raspberry pi.
2.I have tried to use task scheduoer but Im not the admin of my pc and it never works like it should…
I am actually good now - I finally figured out how to run code on my pi!
- MineTurte
-
1000+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
If you don't mind me asking, which one? 1. I have a raspberry pi.
2.I have tried to use task scheduoer but Im not the admin of my pc and it never works like it should…
I am actually good now - I finally figured out how to run code on my pi!
- wvzack
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
- Maximouse
-
1000+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
open() will throw an error if it's called while the other script is using the file. So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
- wvzack
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??open() will throw an error if it's called while the other script is using the file. So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
Last edited by wvzack (Dec. 23, 2024 16:02:45)
- Maximouse
-
1000+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
Is the function in a module that both scripts import? Each script will have a separate instance of the module.What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??open() will throw an error if it's called while the other script is using the file. So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
- davidtheplatform
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
It will probably throw an error. If open gets called twice on the same file without closing the file the first time it throws an error, no matter where it’s being called from. With that being said, json.dumps() should close whatever file it writes to when it’s done, so unless you have some form of parallelism you shouldn’t have any problems.What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??open() will throw an error if it's called while the other script is using the file. So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
- wvzack
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
Yeah I’m using import and then running the function to save a dictionary to the file but his might happen twice at the same timeIt will probably throw an error. If open gets called twice on the same file without closing the file the first time it throws an error, no matter where it’s being called from. With that being said, json.dumps() should close whatever file it writes to when it’s done, so unless you have some form of parallelism you shouldn’t have any problems.What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??open() will throw an error if it's called while the other script is using the file. So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
- davidtheplatform
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
What do you mean by “at the same time”? Are you using a multithreading library or just saving files on a loop, or something else?Yeah I’m using import and then running the function to save a dictionary to the file but his might happen twice at the same timeIt will probably throw an error. If open gets called twice on the same file without closing the file the first time it throws an error, no matter where it’s being called from. With that being said, json.dumps() should close whatever file it writes to when it’s done, so unless you have some form of parallelism you shouldn’t have any problems.What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??open() will throw an error if it's called while the other script is using the file. So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
- wvzack
-
500+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
So I would be monitoring turbowarp and scratch at the same time and they will both be importing the same script which opens/saves text files when a user does something on TW or scratchWhat do you mean by “at the same time”? Are you using a multithreading library or just saving files on a loop, or something else?Yeah I’m using import and then running the function to save a dictionary to the file but his might happen twice at the same timeIt will probably throw an error. If open gets called twice on the same file without closing the file the first time it throws an error, no matter where it’s being called from. With that being said, json.dumps() should close whatever file it writes to when it’s done, so unless you have some form of parallelism you shouldn’t have any problems.What if I call the same function that contains open() twice from different scripts will it only run once and again the next second??open() will throw an error if it's called while the other script is using the file. So I am using json.dumps to dump data into a txt file and I am wondering if I try to call the function that adds a item to the file from 2 scripts at the same time will I corrupt/lose data?
- georgek0
-
79 posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
Hi, any advice on how to publish a module?
- MineTurte
-
1000+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
Hi, any advice on how to publish a module?this should help
Last edited by MineTurte (Jan. 7, 2025 19:02:31)
- kRxZy_kRxZy
-
1000+ posts
PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |
Where can I host python code 24/7 for free, I'm using it for scratch attach
- Discussion Forums
- » Advanced Topics
-
» PyHelp - The official Scratch Python help forum | Ask, help, discuss, & more! | +800 posts! |