[Twisted-Python] "twistd" in Twisted 16.4.0 can't import modules/packages from current working directory

Mark Williams markrwilliams at gmail.com
Thu Sep 1 09:35:51 MDT 2016


On Thu, Sep 01, 2016 at 08:42:02PM +0700, Yuri wrote:
> The errors comes down to this: twistd script does not add current working
> directory to python path (or removes it, I don't know what exactly happens),
> so it fails to import any packages/modules from it. The issue does not
> appear in previous version (Twisted 16.3.2).
>
> Any ideas what caused it?
>
The commits that closed this ticket:
http://twistedmatrix.com/trac/ticket/8491

Generally:
https://github.com/twisted/twisted/commit/c5a4c635de259cd1b92a555c930aa426164f9cce
Specifically:
https://github.com/twisted/twisted/commit/c5a4c635de259cd1b92a555c930aa426164f9cce#diff-a7270bb5043e420fd7a98b81e48ac082

The bin/twistd script would add the current working directory to
sys.path prior to running the actual twistd logic.  This was not
ported over.

I'm going to say that was a conscious decision, as it coincided with
moving twisted to a src/ layout and a fair bit of discussion (visible
in that ticket) about how these changes have made trial only discover
installed code and not whatever's in the current working directory.

To a developer of Twisted it's clear that the project's trying to
replace magical code discovery with boring code importing.  To a user,
that's not clear, and we need to clearly document this.

Being a Twisted developer, I do think in general that it's better to
install your code into an existing sys.path entry instead of adding a
sys.path entry that contains your code.

Would this be difficult for your application, and if so, why?  If it's
possible to make it easier for your application I'd like to help.

Thanks for using Twisted!

-Mark




More information about the Twisted-Python mailing list