[Twisted-Python] Running FTP server as a thread (as opposed to twistd -f ftp.tap)

Jean-Paul Calderone exarkun at divmod.com
Mon Mar 12 14:51:50 MDT 2007


On Mon, 12 Mar 2007 09:49:12 -0700 (PDT), Andy Leszczynski <leszczynscy at yahoo.com> wrote:
>Hi,
>
>I need to launch the twisted based FTP server as a part of my application. I could spawn/control a separate process with subprocess/popen2/etc. However for other reasons I would rather prefer to have it as a separate thread of my app. The question is how to convert mktap generated file into a piece of python code.

You can't run just an FTP server in a thread, but you can run the whole
reactor in a thread.  If the rest of your application doesn't use Twisted,
this might make sense.  Of course, if the rest of your application does
use Twisted, you don't need to get threads involved.

The threaded approach looks something vaguely like this (untested):

  from threading import Thread

  from twisted.tap.ftp import makeService
  from twisted.internet import reactor

  svc = makeService({configuration options})
  reactor.callWhenRunning(svc.startService)
  Thread(target=reactor.run, args=(False,)).start()

  ...
  




More information about the Twisted-Python mailing list