Hey guys, I'm running a Flask webapp using twisted, and I now want to daemonize the process. So I'm trying to use the daemonize PyPI package, which does the common things (forks, sets fd 0/1/2 to /dev/null, etc), however my reactor crashes when daemonized, it tries to close an invalid file descriptor which is just some python file that was read earlier.
The whole thing is baffling, the file descriptor was it reading some random .py file while importing modules, but that was closed previously by python (once it finished reading it I suppose) and now twisted tries to do something with it and I have no idea what's wrong
Could someone please point me the right way? I'm a bit lost
Frantic: Yes but *why* do you want to daemonize :)?
Frantic: The right way generally is not to daemonize.
Juhaz
and why do you want to do it using some third party tool instead of using twistd?
tos9
And to just use `twistd -n web`, or the newer `twist web`
Frantic
tos9: I know, but my company's ops requires that something they manage detach from the terminal and daemonize
clokep has quit
Juhaz: I don't know what you mean by "using twistd"
tos9: I mean, if it were up to me, I would have it not detach and use a process manager such as supervisord or something, but it's not up to me in this case
tos9
That sounds like quite a silly thing if they require every process to implement daemonization and not use any process managers :P
But yes, OK, if you do need to, just use twistd web
`twistd web --wsgi myapp.app` is a daemonizing WSGI container.
Frantic
tos9: I have used twistd before for that, but in this case I need to do a bit of setup beforehand, for example I need to grab some info from commandline, read some config from file, etc. I suppose I could use twistd but need to figure out a way of using it from the python app
tos9
Frantic: That is what you do in myapp.app.
Or in a twistd plugin if you'd like.
Frantic
tos9: But I don't know the port for example until after I run my config code
I could technically have the main python script os.system('twistd ...') but that would be hacky
So I'm trying to find a way of daemonizing just like twistd does
Juhaz
the config code would be in the twistd plugin
or be ran by it
Frantic
Juhaz: correct me if I'm wrong, but doesn't `twistd web` take the --port option? If so, how can my module later define the port?
BTW, I'm not very experienced with twisted, so please tell me if my assumptions are wrong
I suppose what I'd like is: Given a function that configures a reactor, what's the best way to daemonize that and run the reactor
Juhaz
ah, yeah, I guess "web" is the plugin in that case.
Frantic
I don't follow
Juhaz
I mean web is a twistd plugin, but since it's a ready-made one it won't run your code, I was thinking of self created plugins.
Frantic
yes, I'm digging through the twisted.web code, but it's a bit hard to figure out what's going on there
tos9: I've found what you meant by doing it 'in a twisted plugin', but that means my runner needs to be managed by twistd. My app needs to run in two modes: 1) Local test run, and 2) Managed daemon run. I need to use my own runner (e.g. argparser, etc) for option 1)
faldridge joined the channel
clokep joined the channel
OK, I've stopped using the python-daemonize package and instead wrote my own small daemonize function which does the expected things, and the twisted reactor is no longer crashing
I still have no idea what was casing the weird crash though, but whatever, I've spent so much time reading up on this that I've learned what daemonizing needs to be exactly
faldridge has quit
faldridge joined the channel
thanks for the ideas guys
runciter joined the channel
tonythomas joined the channel
faldridge has quit
faldridge joined the channel
LionsMane joined the channel
faldridge has quit
rajesh joined the channel
kenaan
new core enhancement https://tm.tl/#8842 by Stibbons: Readers/Writer Deferred Lock