Python 3.3.4: python-daemon-3K ; How to use runner

2024/10/9 20:28:12

Struggling to try and get a python daemon to work using Python 3.3.4. Im using the latest version of the python-daemon-3K from PyPi i.e. 1.5.8

Starting point is the following code found How do you create a daemon in Python? code i believe is 2.x Python.

import time
from daemon import runnerclass App():def __init__(self):self.stdin_path = '/dev/null'self.stdout_path = '/dev/tty'self.stderr_path = '/dev/tty'self.pidfile_path =  '/tmp/foo.pid'self.pidfile_timeout = 5def run(self):while True:print("Howdy!  Gig'em!  Whoop!")time.sleep(10)app = App()
daemon_runner = runner.DaemonRunner(app)
daemon_runner.do_action()

Attempting to run this i get the following error.

python mydaemon.py start
Traceback (most recent call last):File "mydaemon.py", line 60, in daemon_runner = runner.DaemonRunner(app)File "/depot/Python-3.3.4/lib/python3.3/site-packages/python_daemon_3K-1.5.8-py3.3.egg/daemon/runner.py", line 89, in initapp.stderr_path, 'w+', buffering=0)ValueError: can't have unbuffered text I/O

Any pointer how to translate to work with Python 3.3.4 or a good example of using the runner in python-daemon-3K

Thanks derek

Answer

To make the code run in python3 you need to make a change in the DaemonRunner class, you cannot have unbuffered text IO but you can have unbuffered bytes IO so changing the mode to'wb+' will work:

class DaemonRunner(object):self.parse_args()self.app = appself.daemon_context = DaemonContext()self.daemon_context.stdin = open(app.stdin_path, 'r') # for linux /dev/tty must be opened without buffering and with bself.daemon_context.stdout = open(app.stdout_path, 'wb+',buffering=0)# w+ -> wb+self.daemon_context.stderr = open(app.stderr_path, 'wb+', buffering=0)
https://en.xdnf.cn/q/69978.html

Related Q&A

How to select specific data variables from xarray dataset

BACKGROUND I am trying to download GFS weather data netcdf4 files via xarray & OPeNDAP. Big thanks to Vorticity0123 for their prior post, which allowed me to get the bones of the python script sort…

List object has no attribute Values error

I would like to get the data to Excel worksheet. The problem is when I run the whole code I receive an error but when I run it separately no error it works. Here is what I want; from xlwings import Wor…

How to resize an image in python, while retaining aspect ratio, given a target size?

First off part of me feels like this is a stupid question, sorry about that. Currently the most accurate way Ive found of calculating the optimum scaling factor (best width and height for target pixel …

How to limit number of followed pages per site in Python Scrapy

I am trying to build a spider that could efficiently scrape text information from many websites. Since I am a Python user I was referred to Scrapy. However, in order to avoid scraping huge websites, I …

Why is Pythons sorted() slower than copy, then .sort()

Here is the code I ran:import timeitprint timeit.Timer(a = sorted(x), x = [(2, bla), (4, boo), (3, 4), (1, 2) , (0, 1), (4, 3), (2, 1) , (0, 0)]).timeit(number = 1000) print timeit.Timer(a=x[:];a.sort(…

How to efficiently unroll a matrix by value with numpy?

I have a matrix M with values 0 through N within it. Id like to unroll this matrix to create a new matrix A where each submatrix A[i, :, :] represents whether or not M == i.The solution below uses a lo…

Anaconda Python 3.6 -- pythonw and python supposed to be equivalent?

According to Python 3 documentation, python and pythonw should be equivalent for running GUI scripts as of 3.6With older versions of Python, there is one Mac OS X quirk that you need to be aware of: pr…

Good way of handling NoneType objects when printing in Python

How do I go about printin a NoneType object in Python?# score can be a NonType object logging.info("NEW_SCORE : "+score)Also why is that sometime I see a comma instead of the + above?

problems with easy_install pycrypto

Im trying install pycrypto on osx with easy_install and Im getting the following error:easy_install pycrypto Searching for pycrypto Reading http://pypi.python.org/simple/pycrypto/ Reading http://pycryp…

What is the most efficient way to do a sorted reduce in PySpark?

I am analyzing on-time performance records of US domestic flights from 2015. I need to group by tail number, and store a date sorted list of all the flights for each tail number in a database, to be re…