daemon

线程

折月煮酒 提交于 2019-12-20 13:01:59
Python多线程编程(一):threading 模块 Thread 类的用法详解 我们进行程序开发的时候,肯定避免不了要处理并发的情况。 一般并发的手段有采用多进程和多线程。 但线程比进程更轻量化,系统开销一般也更低,所以大家更倾向于用多线程的方式处理并发的情况。 Python 提供多线程编程的方式。 本文基于 Python3 讲解,Python 实现多线程编程需要借助于 threading 模块。 所以,我们要在代码中引用它。 import threading threading 模块中最核心的内容是 Thread 这个类。 我们要创建 Thread 对象,然后让它们运行,每个 Thread 对象代表一个线程,在每个线程中我们可以让程序处理不同的任务,这就是多线程编程。 值得注意的是,程序运行时默认就是在主线程上 创建 Thread 对象有 2 种手段。 直接创建 Thread ,将一个 callable 对象从类的构造器传递进去,这个 callable 就是回调函数,用来处理任务。 编写一个自定义类继承 Thread,然后复写 run() 方法,在 run() 方法中编写任务处理代码,然后创建这个 Thread 的子类。 1. 直接创建 Thread 对象。 class threading . Thread ( group = None , target = None ,

Can I have some code constantly run inside Django like a daemon

谁都会走 提交于 2019-12-20 10:46:16
问题 I'm using mod_wsgi to serve a django site through Apache. I also have some Python code that runs as a background process (dameon?). It keeps polling a server and inserts data into one of the Django models. This works fine but can I have this code be a part of my Django application and yet able to constantly run in the background? It doesn't need to be a process per se but a art of the Django site that is active constantly. If so, could you point me to an example or some documentation that

Does endless While loop take up CPU resources?

只愿长相守 提交于 2019-12-20 09:36:42
问题 From what I understand, you write your Linux Daemon that listens to a request in an endless loop. Something like.. int main() { while(1) { //do something... } } ref: http://www.thegeekstuff.com/2012/02/c-daemon-process/ I read that sleeping a program makes it go into waiting mode so it doesn't eat up resources. 1.If I want my daemon to check for a request every 1 second, would the following be resource consuming? int main() { while(1) { if (request) { //do something... } sleep(1) } } 2.If I

Efficient Python Daemon

时光怂恿深爱的人放手 提交于 2019-12-20 08:01:21
问题 I was curious how you can run a python script in the background, repeating a task every 60 seconds. I know you can put something in the background using &, is that effeictive for this case? I was thinking of doing a loop, having it wait 60s and loading it again, but something feels off about that. 回答1: I think your idea is pretty much exactly what you want. For example: import time def do_something(): with open("/tmp/current_time.txt", "w") as f: f.write("The time is now " + time.ctime()) def

垃圾IDEA

不问归期 提交于 2019-12-19 23:58:39
垃圾IDEA太不人性化了,做啥都不方便。看不惯他有干不死他。 啥操作都不方便。 今天建个Android项目。找半天都不知道咋运行。 垃圾。网上都没教程。连建个空activity都不行。 org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'MyApplication'. at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:94) at org.gradle.configuration.project.LifecycleProjectEvaluator.doConfigure(LifecycleProjectEvaluator.java:66) at org.gradle.configuration.project.LifecycleProjectEvaluator.access$100(LifecycleProjectEvaluator.java:34) at org.gradle.configuration.project.LifecycleProjectEvaluator

How to keep a persistent PHP script running?

只谈情不闲聊 提交于 2019-12-18 21:19:23
问题 I have a PHP script that listens for incoming socket requests, etc. I need this script to be continually running (it runs within an infinite loop) on the server. How can I initiate and manage this process? I tried just starting it up through SSH/putty but as soon as the SSH connection times out the script dies. 回答1: myscript.php & This will run the scriptin the background you can check it with ps aux | grep myscript.php As Patrick has mentioned in the comments below, there is no maximum

How to package a Python daemon with setuptools

自古美人都是妖i 提交于 2019-12-18 15:51:54
问题 How do you package a Python app with setuptools so that when it's installed (e.g. via setup.py or pip), it places a daemon script in the appropriate location, starts it, and marks it to automatically start at boot time? In my case, my code only works with Linux, so I only care about installing the daemon in Linux environments (specifically Ubuntu). I've found several posts describing how to easily create Python daemons, but I can't seem to find anything describing how you'd install them in a

Best way to daemonize Java application on Linux [closed]

你离开我真会死。 提交于 2019-12-18 12:38:09
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . While I found this question being answered here on SW several times, I didn't find a concluding answer what is the best approach. I'm not looking to use any external wrapper, as I found them launching the java process under a nice level lower then themselves which potentially

Why MUST detach from tty when writing a linux daemon?

醉酒当歌 提交于 2019-12-18 10:51:14
问题 When i tried to write a daemon under linux using C, i was told i should add following code after fork code block: /* Preparations */ ... /* Fork a new process */ pid_t cpid = fork(); if (cpid == -1){perror("fork");exit(1);} if (cpid > 0){exit(0);} /* WHY detach from tty ? */ int fd = open("/dev/tty", O_RDWR); ioctl(fd, TIOCNOTTY, NULL); /* Why set PGID as current PID ? */ setpgid(getpid(), 0); My question is: Is there a must to do the above operations? 回答1: You must disassociate your daemon

How to write a Java daemon

随声附和 提交于 2019-12-18 10:45:37
问题 This will be a network application that will always (or near as always as I can manage) be listening on a given port. I'm fairly new to Java, and very new to non-web server side programming, so I'd like to get feedback from the community on my assumptions and preliminary plans. I've read about jsvc ( http://commons.apache.org/daemon/jsvc.html ) and am currently operating on the assumption that this is the "best" way to write a daemon in java for a linux box (likely running centOS). Can nagios