giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.65k stars 265 forks source link

Inherit IOLoop class in handlers #609

Closed stat1c-void closed 9 months ago

stat1c-void commented 9 months ago

This change allows FTPHandler to inherit a concrete IOLoop class from FTPServer. Without it, it makes customizing an IOLoop harder than it needs to be: any custom IOLoop passed to FTPServer does not get inherited by handlers right now, because of this (_SpawnerBase in servers.py):

    def _loop(self, handler):
        """Serve handler's IO loop in a separate thread or process."""
        with IOLoop() as ioloop:

Other approaches

This looks ugly and makes assumptions about the constuctor:


    def _loop(self, handler):
        """Serve handler's IO loop in a separate thread or process."""
-       with IOLoop() as ioloop:
+       with self.ioloop.__class__() as ioloop:

Another one is to introduce a new FTPServer argument ioloop_factory - a callable factory.


    def _loop(self, handler):
        """Serve handler's IO loop in a separate thread or process."""
-       with IOLoop() as ioloop:
+       with self.ioloop_factory() as ioloop:

Tests

Linux, Python 3.10.12.

Ran 795 tests in 28.538s

OK (skipped=55)
giampaolo commented 9 months ago

Seems reasonable.