Hello,
I have finally gotten to a stage where I want to run my very large
application as a daemonized twisted app, and I have two questions:
1) The program uses multiple UDP/TCP clients and servers that are
currently launched with reactor.listenTCP / UDP connectTCP/UDP etc. I've
been using MultiService, according to the twisted documentation.
Some of these services were are at a top level of my app so it was easy
to turn that part into a .tac file and switch the reacor calls to
internet.…
[View More]TCPServer etc.
However, some of them are deep inside my code, and are instantiated on
the fly.
What is the "right" way to attach them to my service parent? (the part
with ".setServiceParent(<myMultiservice>")
Should I now add a pointer to my MultiService that will be propagated
down the code hierarchy to each of these calls and be accessible at the
inner scopes?
Is there a neater way to do it just with importing the right modules?
(in the same way that in usual twisted scripts the loaded reactor is a
global reactor)
2) There are still scenarios where I would want to run my code the
"reactor" way rather than than using the application framework, and I
would love to be able to keep a single file that's compatible with both
modes..
Is there a way to detect in runtime whether the code is being run
through 'twistd' and the app framework or if its run directly?
I was thinking of doing something like:
if <test if we are run as an app>:
internet.TCPServer(<port>,<factory>).setServiceParent(<myMultiservice>)
else:
reactor.listenTCP(<port>,<factory>)
Thanks!
Nadav
[View Less]