Closed morganwahl closed 5 years ago
I've confirmed the stream being written to is open in non-blocking mode.
I defined this function:
def print_flags(filehandle):
print("file:", filehandle, filehandle.fileno())
flags = fcntl.fcntl(filehandle, fcntl.F_GETFL)
print("\tflags:", hex(flags))
for attr in dir(os):
if attr.startswith('O_'):
flag = getattr(os, attr)
if flags & flag:
print("\tflag {} {:x}: {:x}".format(attr, flag, flags & flag))
and then added this __init__
to TeamcityTestRunner
:
def __init__(self, *args, **kwargs):
super(TeamcityTestRunner, self).__init__(*args, **kwargs)
print("testrunner init")
print_flags(self.stream)
I then this this output in the build log:
[14:49:52]
[Step 1/1] testrunner init
[14:49:52]
[Step 1/1] file: <unittest2.runner._WritelnDecorator object at 0x7f85d52c1710> 2
[14:49:52]
[Step 1/1] flags: 0x801
[14:49:52]
[Step 1/1] flag O_NDELAY 800: 800
[14:49:52]
[Step 1/1] flag O_NONBLOCK 800: 800
[14:49:52]
[Step 1/1] flag O_WRONLY 1: 1
I think the correct fix for this is to catch the exception and retry. I'll see if I can PR that change, and/or a regression test.
Not sure. Do you know why it's in NONBLOCK mode? If it is, write call maybe also throw an exception. I don't think the right way is to decorate all of them with a retry.
I have no clue why it's non-blocking. Maybe because a parent process made it that way? Or maybe it's something in unittest
itself?
Another approach would be to change it to blocking, somehow.
If it helps, this is run in a build config step that executes a single command. That command is a shell script we've written, which in turn invokes the Django management command to run the tests.
[closed on accident]
Our tests occasionally fail when run on TeamCity with a traceback like this:
As you can see, we're running regular python unittests, using django's test-running system.
From what I've read, I wouldn't expect an IO operation like
flush()
to result in this error unless the file was in non-blocking mode. Is it possible stdout is non-blocking when being run by teamcity?