Also einen pdb konnte ich nicht finden, nur einen winpdb und damit komme ich herzlich besch****n zurecht. Was ich bisher herausgefunden habe ist folgendes.
Ich habe den Code ungefähr so:
Code: Alles auswählen
import daemon
import os
import sys
import time
import serial
import ConfigParser
import mpd
import getopt
import pwd
import syslog
import string
...
...
...
def mpd_Play():
bla()
def mpd_Next():
bla()
...
...
daemon.daemonize()
syslog.syslog(0, 'bla')
...
def my_daemon:
bla()
blubb()
das_eigentliche_hauptprogramm()
...
...
my_daemon()
Die Imports sind genau so, wie ich sie im Code habe.
Da hängt er sich auf, aber schreibe ich wie im Eingangsbeitrag das stark verkürzte hin, dann geht es seltsamerweise...
Code: Alles auswählen
#!/usr/bin/env python
import syslog
import daemon
datei = open('datei', 'a')
daemon.daemonize()
datei.write('bla')
datei.close()
syslog.syslog(0, 'bla')
while(1):
a=0
bla steht in datei und im syslog und
ps aux | grep python zeigt mir den Prozess auch an...
Auch wenn ich alle imports reinpacke, geht es.
Wegen dem Debugger, kann mir jemand sagen, nach WAS ich Ausschau halten soll?
Etwas, was mir aufgefallen ist, ist, sobald er (siehe code ganz oben) my_daemon() aufruft, kommt im Frame mit dem Script das Script zu deamon und es wird zwar noch in der Konsole angezeigt was vor meinem
daemon.daemonize() angezeigt wird (print) aber ich sehe im debugger kein einziges mal wie ich dort einen Schritt weiter gehe, er geht direkt in das Script zu daemon und landet dort:
Code: Alles auswählen
def __fork():
global g_forktid
if not g_fignorefork:
g_forktid = setbreak()
#
# os.fork() has been called.
#
# You can choose if you would like the debugger
# to continue with the parent or child fork with
# the 'fork' console command.
#
# For example: 'fork child' or 'fork parent'
# Type: 'help fork' for more information.
#
# WARNING:
# On some Posix OS such as FreeBSD,
# Stepping into the child fork can result in
# termination of the child process.
#
# *** RPDB2 SAYS: Read the entire comment! ***
#
return g_os_fork()
Einen weiteren step später:
Code: Alles auswählen
def _fork():
try:
return os.fork()
except OSError, e:
raise DaemonException, 'Cannot fork: %s [%d]' % (e.strerror, e.errno)
Weiter, und hier steigt er dann aus, dort wo das "######## HIER!" steht, was aber, wie ich sehe doch nur für den Vaterprozess sein soll...
Code: Alles auswählen
def daemonize(noClose=False):
"""
Convert the calling process into a daemon.
@type noClose: boolean
@param noClose: If True, don't close the file descriptors. Useful
if the calling process has already redirected file
descriptors to an output file. WARNING: Only set this
parameter to True if you're SURE there are no open file
descriptors to the calling terminal. Otherwise, you'll
risk having the daemon re-acquire a control terminal,
which can cause it to be killed if someone logs off that
terminal.
@raise DaemonException: Error during daemonizing
"""
global log
if os.name != 'posix':
log.warn('Daemon is only supported on Posix-compliant systems.')
return
try:
# Fork once to go into the background.
log.debug('Forking first child.')
pid = _fork()
if pid != 0:
# Parent. Exit using os._exit(), which doesn't fire any atexit
# functions.
os._exit(0)
# First child. Create a new session. os.setsid() creates the session
# and makes this (child) process the process group leader. The process
# is guaranteed not to have a control terminal.
log.debug('Creating new session')
os.setsid()
# Fork a second child to ensure that the daemon never reacquires
# a control terminal.
log.debug('Forking second child.')
pid = _fork()
########## HIER !
if pid != 0:
# Original child. Exit.
os._exit(0)
..
..
Unix confuses me