pyftpdlib in thread -> how to quit?

1182 views
Skip to first unread message

kos...@gmail.com

unread,
Oct 3, 2012, 4:19:07 PM10/3/12
to pyft...@googlegroups.com
Hi, 
1. amazing work with pyftpdlib :) 
2. I have this small issue -> 
I have a special server (3D models remote rendering). It has pyftpdlib built-in for certain reasons. But I need my server no to hang at "ftp_server.server_forever()". I solved this by creating a Ftp server class like this:

class RenderServerFTP(ftpserver.FTPServer, Thread):

    '''

    classdocs

    '''



    def __init__(self):

       

        

        Thread.__init__(self)

        self.authorizer = ftpserver.DummyAuthorizer()

        try:

            self.authorizer.add_user#### BLA BLA

        except ValueError,e:

            Logger.warn(self.__class__.__name__ + " : Error starting FTP server, creating dir for storing models")

            try:

                os.makedirs(join(expanduser("~"), ".arhell"))

            except OSError,e:

                pass

            os.makedirs(join(expanduser("~"), ".arhell", "models"))

            self.authorizer.add_user# BLA BLA BLA

        self.handler = ftpserver.FTPHandler

        self.handler.authorizer = self.authorizer

        ftpserver.FTPServer.__init__(self, ("0.0.0.0", 15021), self.handler)

        

    def run(self):

        self.serve_forever()


=> so it is a thread that doesnt hang. BUT how do I stop the server??? Calling close_all() or close() from a different Thread (3D render server) causes an error:

Shutting down FTP server

 Exception in thread Thread-1:

 Traceback (most recent call last):

   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 530, in __bootstrap_inner

     self.run()

   File "/Volumes/Kosta_Home/homes/kosta/git/kivyarhellgui/network/RenderServerFTP.py", line 39, in run

     self.serve_forever()

   File "/Library/Python/2.7/site-packages/pyftpdlib/ftpserver.py", line 3751, in serve_forever

     poll_fun(timeout)

   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py", line 140, in poll

     r, w, e = select.select(r, w, e, timeout)

 error: (9, 'Bad file descriptor')


Any ideas how I can fix this? The FTPserver thread is stuck in its self.run() (self.server_forever()) and is not aware of me trying to quit it from another thread...

thanks




Giampaolo Rodolà

unread,
Oct 3, 2012, 4:22:15 PM10/3/12
to pyft...@googlegroups.com
Hi there,
you might want to take a look at the thread-based FTP server used in pyftpdlib test suite:

It does exactly what you're asking:

- doesn't block on serve_forever()
- can be stopped
- can also be restarted


G.

2012/10/3 <kos...@gmail.com>

--
You received this message because you are subscribed to the "Python FTP server library" project group:
http://code.google.com/p/pyftpdlib/
To post to this group, send email to pyft...@googlegroups.com
To unsubscribe from this group, send email to pyftpdlib-...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/pyftpdlib

kos...@gmail.com

unread,
Oct 9, 2012, 6:17:11 AM10/9/12
to pyft...@googlegroups.com
Thank you very much, 

I got to it now finally and that was exactly what I was looking for

Dne středa, 3. října 2012 22:22:17 UTC+2 Giampaolo Rodolà napsal(a):

karl.ri...@gmail.com

unread,
May 16, 2014, 4:49:41 AM5/16/14
to pyft...@googlegroups.com, kos...@gmail.com
Could one of you maybe (after this long time) post the relevant code parts because I can't figure them out from the > 3000 lines test case. I guess it would be nice to add this to the tutorial, too (I'd like to file an enhancement request for it or the docs, afterwards).

Best regards,
Kalle

Giampaolo Rodola'

unread,
May 16, 2014, 4:58:48 AM5/16/14
to pyft...@googlegroups.com, kos...@gmail.com
The test server class is here:
For now you can copy and paste it.
There's a plan to move the test server:
...but I still have to get around to it.


---
You received this message because you are subscribed to the Google Groups "Python FTP server library - Discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyftpdlib+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages