Closed trunet closed 5 years ago
Hi there,
from the output I guess that you specifyed the port as in the example in the readme ( FTP_PORT=31175
).
As I understand it celery
runs tasks in parallel, so there is already an ftp instance listening on port 31175 and there can't be more than one task listening on the same port, which is why it raises an error.
Possible solution:
FTP_PORT=31175
from your config, like that the port should get chosen as any free portftpserver.get_login_data()["port"]
If that doesn't help, please share your tox.ini
/ pytest.ini
and maybe make a minimal example to reproduce the error.
P.S.: Please keep us in touch if it works, so we can add it to the docs 😄
It's something I have seen too while using a Mac, like you do. It'll be hard to weed out since I don't use a Mac and @s-weigand uses windows. See if using the process based instead of thread based class works better.
Thanks for the prompt reply, I appreciate it.
@s-weigand yes, celery runs in parallel, but I think not the tests, they should be serial. I'm using a function scope fixture (celery_worker). Per documentation, it starts a worker, run the task and stop the worker after the test function ends.
I followed your suggestion 1. 2, were already in place. Now I don't get the error after running one test right after the other. Somehow the ftp port stays listening for around 10 seconds after the test finishes.
@oz123 I understand. I tried to set USE_PROCESS = True for darwin (osx) as well, and the test hangs.
I will do some more troubleshooting tomorrow. A question I have is why did you implemented your own Thread/Process class instead of using pyftpdlib.servers classes?
@trunet thanks for the tip with the extended servers i will have a look at them 😃
So I did play around with ThreadedFTPServer
and MultiprocessFTPServer
from pyftpdlib
, but they have the same problem as the normal FTPServer
, server.serve_forever()
blocks all other actions if run in the main thread. Even if you start the server with server.serve_forever(blocking=False)
the tests hang, which is why we run the server in a separate thread/process. ThreadedFTPServer
and MultiprocessFTPServer
run also in the main thread, but start a new task as thread/process for each new connection.
@trunet how did you find out, that the server is listening around 10 seconds after the test finishes? Sadly I can't reproduce your error, so it's hard to debug.
Before taking FTP_PORT out, when I ran the tests right after a completed one 'Address already in use' triggers.
Like 'tox; tox', exception. 'tox; sleep 5; tox', exception. 'tox; sleep 10; tox', success.
I have a jenkins job for this running on a linux slave. When running from linux slave, I don't have any error, so the 'OSError: [Errno 9] Bad file descriptor' traceback is macosx only apparently.
Could you maybe provide a minimal example to reproduce the error?
It might help to extend the stop
method of ThreadFTPServer
like this:
def stop(self):
self._server.stop()
self.join()
But since I can't reproduce the error this is just a guess, at least it's not breaking our tests.
Hello,
I'm trying to use ftpserver mock to test some parts of my code. It's running together with celery_worker fixture, as I need an ftpserver available to send files from a celery task
The test succeeds, even though the traceback is showing.
Using:
If I ran the tests just after another one, I got multiple
OSError: [Errno 48] Address already in use
. First is a success (with the traceback):Second, sometimes it's the same as above, but if it's right after the previous run, I got:
Can you help me with that?