D
D
Dmitry Sergeev2018-02-17 21:05:17
linux
Dmitry Sergeev, 2018-02-17 21:05:17

How to run a python script as a service on linux?

The simplest script

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys

# тут происходит очень тяжёлая штука, которая занимает много времени. она нужна далее для обработки введенного текста и вывода результата. именно поэтому хочу чтобы скрипт работал как сервис и постоянно висел в памяти.

if len(sys.argv) == 2:
    text = str(sys.argv[1]);
    text = "You enter:" + text;
    print(text)

> python test_demon.py hello You
enter : hello

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Nikolaev, 2018-02-18
@JetMaster

The demon is not needed here at all, this is not what it is needed for.
Make the script executable
Create a symlink or to any directory from the PATH variable
Use as described
test_demon hello

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question