Mac OS Run a python script when an app is launched - python

Is there a way to start a python script in the terminal every time I start a specific application?
I need a script to be running in the background to work with a software, but if I forget to start it before I launch the app, I have to shut down everything, start the script and reopen the app.
I tried in automator, but I couldn't find a trigger for when app is launched.

Related

Best practice for starting and running django server without terminal

Im developing a django erp application and want to run it without stop. If we do runserver from a terminal it may be stopped at a point of time automatically. So what i seek for is to tell the os to run django as it boot up. Can subprocess of python a good idea to call from cron at startup ?

How to automatically launch django web server by windows SYSTEM

I want to know if there's a way to have windows server 2019 automatically launch django's web server. I also want the launch to be performed at startup and by SYSTEM.
I tried using batch scripts that launch manage.py from venv's python interpreter. When I launch the batch manually (i.e. double click) it works fine and dandy. But it appears that SYSTEM fails in running the script correctly when planning the task.
I made SYSTEM launch another script at startup (a simple python script that creates a txt file from within its own venv) and it works.
If the Django launch sceipt is launched by USER then it works.
The problem is with the launching of django with SYSTEM. I've also tried streamlit and the result is the same.
Do you have any Ideas?
Sample batch script:
cd path\of\managepyfile\
C:\path_to_venv\Scripts\python -m manage.py runserver
We run a similar application (not python) but an application that uses a web server.
We have it setup as a task in task scheduler that when the server starts up, it runs the powershell script that executes a command to start the web server.
Link to setup
However, you could use a web server like IIS and deploy the files to the www folder in the cdrive and run the site as an IIS service.
Setting it up on IIS was a little tricky if you've never used IIS before. Happy to help out as we have deployed our test access tool for one of our apps this way.

Run PyCharm with command on PC Startup

I am using PyCharm in two instances for crypto-trading. Currently when my computer starts up, I would have to open both projects on PyCharm manually and enter two different commands manually.
Is there a way to run these projects with the commands needed automatically right after starting my computer?
A better way to start your bot on startup is to add your python script or something in a startup or run your python script as a service.
Check out this article

Linux - Open chromium from a script that runs on startup

I have a bash script that I've defined to run in startup, which runs a python script that waits for a command from another process, and when it gets it, it should open a chromium window with a certain URL.
When I run this script manually it works fine, but when the script runs from startup, I get an error (displayed in syslog):
Gtk: Can't open display
I guess that's because it's running in a startup mode so it doesn't actually have a display to "lean" on...
I was wondering if there's any way to get this work, anyway?
Thanks in advance
In your script that runs on startup try DISPLAY=:0 <command> &
To clarify DISPLAY=:0 simply sets which monitor your window opens on with 0 representing the first monitor of the local machine.

Bokeh application development workflow

I'd like to develop a Bokeh application and based on the documentation, it seems best to run the bokeh serve --show app.py locally when developing the application.
After running the command, the application launches in a new browser tab and works correctly. However, it's not clear to me how to edit the code and rerun the application because once the tab is closed, the application continues to run in the terminal and the only way to exit is through kill <pid> which is somewhat inconvenient.
What is a good workflow for developing a Bokeh application?
If you are on a mac, you can stop the application with ctrl+c from terminal. This will shut down the app. Then you edit the code, save it and rerun bokeh serve --show app.py from terminal. That's all.
Note that the application should continue running as long as your browser window is open. If you change the inputs using the widgets in your dashboard it will print out logging in terminal, as it updates the dashboard according to your code.
Closing the tab will only close the client session. To kill the server process, indeed you need to kill the process somehow. Ctrl+c is convenient from the terminal. If you are in an IDE like PyCharm, I suggest setting up your configuration to run bokeh like a python script via python -m bokeh serve --show. Then you can use your IDE's start/stop/restart functionality also.
FYI if you are in Pycharm 2017.x, your script name should be the script or directory (for directory-based apps) of the bokeh app and interpreter options should be -m bokeh serve --show
I typically also set up another configuration for debugging which runs the script like a typical python script (no special interpreter args). This will allow you to use your IDE's debugger for any issues basically up to the initial page load. For any debugging beyond that (i.e. callbacks), I typically use a combination of logging and/or manual pdb.set_trace() calls.

Categories

Resources