[Twisted-Python] odd problem with daemonization?

I've got a pretty simple server using a factory and some protocol objects. This code handles access to an extension module (the details of which are probably not useful, but it is written in C++, wrapped with SWIG) which implements the majority of our application logic. The C++ code tends to dump a ton of output to stdout, and when I twistd like this: twistd -f myveryown.tap and have a connected protocol instance, the log out put from the C++ code end up getting written directly to the socket and sent to the client. When I run things like this: twistd -n -f myveryown.tap Things are just fine and nothing goes wrong in that part of the code. I do use twisted.python.log in the Python side of things. The protocol is a child of twisted.protocols.basic.Int32StringReceiver. I haven't yet tried to come up with a more minimal test case, but will try later tonight if no one has any thoughts. - Bruce

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday, March 18, 2003, at 05:08 PM, Bruce Mitchener wrote:
Just a brief word of warning... while I've had a few good experiences integrating C/C++ code with Python, SWIG has uniformly been horrible. This particular issue is not with SWIG, but it may create interference later on.
The reason that you're having this problem is that on the C++ side of things, FD 0,1,2 are just normal FDs. This is due to the fact that we trap the sys.stdout _object_ in python, but we don't keep the file-descriptors around. The Transport of your Protocol is getting created after those FDs have been closed, and is therefore haplessly allocating the FD of stdout by chance. I don't know how to create a file-descriptor in C which translates to function calls on a Python file-type object. In fact, I don't even know if that's possible. However, this is clearly incorrect behavior for cout<< and printf. Can anyone with more experience in this area propose a solution? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE+eAgKvVGR4uSOE2wRAkREAJsG/w54utuFUiGoOF5sFTosC0mUyACfWmqk t7YY/4sBaVjtoZQpoqo1YAA= =ygqD -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday, March 20, 2003, at 01:03 AM, Tommi Virtanen wrote:
Hmm. What about using pipes that are funneled to the logger for 1 and 2, and just dup2'ing 0 to /dev/null? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE+ejg5vVGR4uSOE2wRAsU0AJ9/ajbl4Opm3fawaw3hpBY2zhztUACfSS4p ZxhdWIQtJfjXehNB6i8f9ds= =oYUh -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tuesday, March 18, 2003, at 05:08 PM, Bruce Mitchener wrote:
Just a brief word of warning... while I've had a few good experiences integrating C/C++ code with Python, SWIG has uniformly been horrible. This particular issue is not with SWIG, but it may create interference later on.
The reason that you're having this problem is that on the C++ side of things, FD 0,1,2 are just normal FDs. This is due to the fact that we trap the sys.stdout _object_ in python, but we don't keep the file-descriptors around. The Transport of your Protocol is getting created after those FDs have been closed, and is therefore haplessly allocating the FD of stdout by chance. I don't know how to create a file-descriptor in C which translates to function calls on a Python file-type object. In fact, I don't even know if that's possible. However, this is clearly incorrect behavior for cout<< and printf. Can anyone with more experience in this area propose a solution? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE+eAgKvVGR4uSOE2wRAkREAJsG/w54utuFUiGoOF5sFTosC0mUyACfWmqk t7YY/4sBaVjtoZQpoqo1YAA= =ygqD -----END PGP SIGNATURE-----

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday, March 20, 2003, at 01:03 AM, Tommi Virtanen wrote:
Hmm. What about using pipes that are funneled to the logger for 1 and 2, and just dup2'ing 0 to /dev/null? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.1 (Darwin) iD8DBQE+ejg5vVGR4uSOE2wRAsU0AJ9/ajbl4Opm3fawaw3hpBY2zhztUACfSS4p ZxhdWIQtJfjXehNB6i8f9ds= =oYUh -----END PGP SIGNATURE-----
participants (4)
-
Bruce Mitchener
-
Glyph Lefkowitz
-
Jeremy Noetzelman
-
Tommi Virtanen