Popular recipes tagged "daemon"http://code.activestate.com/recipes/tags/daemon/popular/2015-06-30T03:24:07-07:00ActiveState Code RecipesConsumer Application Skeleton (Python)
2015-06-30T03:24:07-07:00Vovanhttp://code.activestate.com/recipes/users/4192447/http://code.activestate.com/recipes/579074-consumer-application-skeleton/
<p style="color: grey">
Python
recipe 579074
by <a href="/recipes/users/4192447/">Vovan</a>
(<a href="/recipes/tags/application/">application</a>, <a href="/recipes/tags/consumer/">consumer</a>, <a href="/recipes/tags/daemon/">daemon</a>, <a href="/recipes/tags/framework/">framework</a>).
Revision 2.
</p>
<h4 id="consumer-application-skeleton">Consumer Application Skeleton</h4>
<p>This is very basic skeleton for data processing application implementing
consumer pattern:</p>
<pre class="prettyprint"><code>while is_running():
task = get_next_task_from_queue()
if task:
submit_task_for_processing(task)
else:
sleep_for_a_moment()
</code></pre>
<p>Here's an example:</p>
<pre class="prettyprint"><code>class ExampleApp(ConsumerAppBase):
def _get_next_task(self):
# Get next task from the queue.
return self._queue.next()
def _run_task(self, task):
# This code's being executed in separate worker thread of
# ThreadPoolExecutor
return task / 2
def _on_task_done(self, task, future):
# Once worker thread finished - task results are available
# in _on_task_done() callback as a concurrent.futures.Future object.
self._log.info('Task done. Result: %s', future.result())
</code></pre>
Generic way to create a daemonized process in python (Python)
2012-03-26T14:56:17-07:00ajaymenon.khttp://code.activestate.com/recipes/users/4181225/http://code.activestate.com/recipes/578072-generic-way-to-create-a-daemonized-process-in-pyth/
<p style="color: grey">
Python
recipe 578072
by <a href="/recipes/users/4181225/">ajaymenon.k</a>
(<a href="/recipes/tags/daemon/">daemon</a>, <a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/threads/">threads</a>).
Revision 4.
</p>
<p>A simple daemon that will constantly keep track the size of your inbox and when it exceeds a certain size, will send you a reminder email.</p>
Context manager for a daemon pid file (Python)
2013-10-07T21:03:30-07:00Graham Poulterhttp://code.activestate.com/recipes/users/4172291/http://code.activestate.com/recipes/577911-context-manager-for-a-daemon-pid-file/
<p style="color: grey">
Python
recipe 577911
by <a href="/recipes/users/4172291/">Graham Poulter</a>
(<a href="/recipes/tags/daemon/">daemon</a>, <a href="/recipes/tags/pid/">pid</a>).
Revision 3.
</p>
<p>Context manager for a pid (process id) file used to tell whether a daemon process is still running.</p>
<p>On entry, it writes the pid of the current process to the path. On exit, it removes the file.</p>
<p>Designed to work with python-daemon.</p>
logging support for python daemon (Python)
2010-10-25T15:22:18-07:00Bud P. Brueggerhttp://code.activestate.com/recipes/users/4175472/http://code.activestate.com/recipes/577442-logging-support-for-python-daemon/
<p style="color: grey">
Python
recipe 577442
by <a href="/recipes/users/4175472/">Bud P. Bruegger</a>
(<a href="/recipes/tags/daemon/">daemon</a>, <a href="/recipes/tags/logging/">logging</a>).
</p>
<p>The recipe shows how to subclass python-daemon's [1] DaemonContext to add logging support. In particular, it is possible to ask to keep the files related to a list of loggers (loggers_preserve) open and to redirect stdout and stderr to a logger (e.g., one using a RotatingFileHandler). </p>
<p>[1] See <a href="http://pypi.python.org/pypi/python-daemon/" rel="nofollow">http://pypi.python.org/pypi/python-daemon/</a></p>