Changes between Version 9 and Version 10 of FrequentlyAskedQuestions


Ignore:
Timestamp:
12/14/2006 07:34:55 PM (12 years ago)
Author:
teratorn
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • FrequentlyAskedQuestions

    v9 v10  
    1919=== I have a problem getting Twisted. ===
    2020
    21 Did you check the HOWTO collection? There are so many documents there that they might overwhelm you... try starting from the index, reading through the overviews and seeing if there seems to be a chapter which explains what you need to. You can try reading the PostScript or PDF formatted books, inside the distribution. And, remember, the source will be with you... always.
     21Did you check the HOWTO collection? There are so many documents there that they might overwhelm you... try starting from the index, reading through the overviews and seeing if there seems to be a chapter which explains what you need to. You can try reading the !PostScript or PDF formatted books, inside the distribution. And, remember, the source will be with you... always.
    2222
    2323=== Why are there so many parts and subprojects? Isn't Twisted just Twisted? ===
     
    9696A common problem occurs in single-file programs which define a few classes, then create instances of those classes for use in a server of some sort. If the class is used directly, the name of the class will be recorded in the {{{.tap}}} file as something like {{{__main__.MyProtocol}}}. When the application is reloaded, it will look for the class definition in {{{__main__}}}, which probably won't have it. The unpickling routines need to know the module name, and therefore the source file, from which the class definition can be loaded.
    9797
    98 The way to fix this is to import the class from the same source file that defines it: if your source file is called {{{myprogram.py}}} and defines a class called {{{MyProtocol}}}, you will need to do a {{{from myprogram import MyProtocol}}} before (and in the same namespace as) the code that references the MyProtocol class. This makes it important to write the module cleanly: doing an {{{import myprogram}}} should only define classes, and should not cause any other subroutines to get run. All the code that builds the Application and saves it out to a .tap file must be inside an {{{if __name__ == '__main__'}}} clause to make sure it is not run twice (or more).
     98The way to fix this is to import the class from the same source file that defines it: if your source file is called {{{myprogram.py}}} and defines a class called {{{MyProtocol}}}, you will need to do a {{{from myprogram import MyProtocol}}} before (and in the same namespace as) the code that references the {{{MyProtocol}}} class. This makes it important to write the module cleanly: doing an {{{import myprogram}}} should only define classes, and should not cause any other subroutines to get run. All the code that builds the Application and saves it out to a .tap file must be inside an {{{if __name__ == '__main__'}}} clause to make sure it is not run twice (or more).
    9999
    100100When you import the class from the module using an external name, that name will be recorded in the pickled {{{.tap}}} file. When the {{{.tap}}} is reloaded by twistd, it will look for {{{myprogram.py}}} to provide the definition of {{{MyProtocol}}}.