I have a python script which collects data from Twitter and stores into MongoDb. I need to run this code on the server as a service.
However, only 2 users can remain logged into the server at any given time and therefore If I log out my account, the python script would stop working and data collection will stop.
My question is - How can I run this script as a service on the server such that it keeps running irrespective of whichever user is logged in?
Task Scheduler is the easiest solution I know of. You can use it to run the code at startup as the NT AUTHORITY\SYSTEM user and automatically restart on failure. In case you need it, there's a basic overview of Task Scheduler here.
Related
What does Last Run Result (0xF6) mean?
I scheduled the Task Scheduler to run a *pythonw.exe with the arguments pointed to the *.py file.
User account is set for an admin account
Run whether user is logged on or not
Run with the highest privileges
Configured for Windows 10
I can't find a reference to this in a google search. Whatever is happening via the Task Scheduler I can't really tell because the python script does not finish-- meaning I can't read the log file to check how far it got or if it ran into any errors. If I run the script without the Task Scheduler it completes successfully.
I created a python script to automate a task.
I would like to run it every day on a hourly basis and for this I created a task in Windows Task Scheduler.
Is there a way to write a script to log in Windows automatically when my account is logged out, because my script fails if the Windows user is not logged in.
Thank you.
This is the wrong way to approach this. It's normal and expected that your computer will not always be logged in. You should not try to change that, as it would be very insecure.
The right thing to do is figure out why your script will not run when the system is not logged in. When setting your task up, you can set user credentials it should use when starting. Make sure your program is not making any incorrect assumptions about accessibility or security when it runs.
I have a project in which one of the tests consists of running a process indefinitely in order to collect data on the program execution.
It's a Python script that runs locally on a Linux machine, but I'd like for other people in my team to have access to it as well because there are specific moments where the process needs to be restarted.
Is there a way to set up a workflow on this machine that when dispatched, stops and restarts the process?
You can execute commands on your Linux host via GH Actions and SSH. Take a look at this action.
I have coded a Python Script for Twitter Automation using Tweepy. Now, when i run on my own Linux Machine as python file.py The file runs successfully and it keeps on running because i have specified repeated Tasks inside the Script and I also don't want to stop the script either. But as it is on my Local Machine, the script might get stopped when my Internet Connection is off or at Night. So i couldn't keep running the Script Whole day on my PC..
So is there any way or website or Method where i could deploy my Script and make it Execute forever there ? I have heard about CRON JOBS before in Cpanel which can Help repeated Tasks but here in my case i want to keep running my Script on the Machine till i don't close the script .
Are their any such solutions. Because most of twitter bots i see are running forever, meaning their Script is getting executed somewhere 24x7 . This is what i want to know, How is that Task possible?
As mentioned by Jon and Vincent, it's better to run the code from a cloud service. But either way, I think what you're looking for is what to put into the terminal to run the code even after you close the terminal. This is what worked for me:
nohup python code.py &
You can add a systemd .service file, which can have the added benefit of:
logging (compressed logs at a central place, or over network to a log server)
disallowing access to /tmp and /home-directories
restarting the service if it fails
starting the service at boot
setting capabilities (ref setcap/getcap), disallowing file access if the process only needs network access, for instance
The idea:
There is a Node.JS server which sends a request to the IIS server which is running Django / Python. It will send two files to the server which need to be converted with a program which needs to be run in the foreground mode.
So I already looked around in pretty much everything related to IIS and the running of executables here on SO, but still haven't got it working.
I got the following code to run the application from Django:
subprocess.call("C:\example.exe")
There will be probably be some serious security issues (although the server is only reachable from the local network) with the following setup, but here it is:
I'm running a Django application on IIS.
I've set the Application Pool Identity to my local user
I've given "Full Control" permission to "Everyone"
When the subprocess call gets executed it will add the program to my Background Processes with the USER being set to my local user.
Questions:
How do I make the program start in Desktop Mode?
Should I perhaps add another step (start another service) which will then start the program?
Edit:
Could I perhaps make a file watcher which watches if files get stored on the Windows Server and then triggers an executable based on that?