Running a Twisted Application in PyDev

拈花ヽ惹草 提交于 2020-01-02 06:52:31

问题


I would like to debug a Twisted Application (10.0.0) using the Eclipse (3.5.2) PyDev Module (1.6.4) and Python (2.6.5). To run the application from the command line I would specify the following:

c:\python26\python c:\python26\scripts\twistd.py -ny mytwistedapp.py

To accomplish this using PyDev I created a new PyDev project and imported mytwistedapp.py and twistd.py. Under the project's run configuration I specified c:\python26\scripts\twistd.py as the main module. If I select Run -> Debug Configurations it runs twistd.py with no parameters (half-way there, right?). If I try to add the program arguments to the run configuration (-ny mytwistedapp.py) they are processed by the PyDev debugger instead of twistd.py. Two questions:

  1. Is specifying twistd.py as the main module the right approach?
  2. If so, how can I pass twistd.py the parameters it needs to run mytwistedapp.py (-ny mytwistedapp.py)?

回答1:


First off, thank you all so much for your kind and gracious support in this matter!

The key to running a twisted application via the PyDev module of Eclipse is to define twistd.py as the Main Module in the Run Configuration. The following steps can be used:

These instructions assume you can already run twisted applications on your system, which means you've installed zope and twisted. For example, the following already works for you:

python twistd.py mytwistapp.tac

These instructions also assume that you have already installed and configured PyDev in Eclipse, including the definition of the PYTHONPATH. 1. Navigate to Window -> Preferences -> PyDev -> Interpreter (Python) 2. Under Libraries Tab (System PYTHONPATH), System Libs should already contain location of your Python instllation (e.g., c:\python26, c:\python26\dlls\, c:\python26\lib, etc). 3. Add the Zope egg and the Twisted folder to System libs. For example, c:\python26\lib\site-packages\twisted and c:\python26\lib\site-packages\zope.interfaces-3.6.1-py2.6-win32.egg

Create a new Pydev project

  1. Create a new PyDev project (e.g., MYPROJ)
  2. Import your various twisted application files
  3. * Add twistd.py to your project *. Rather than adding a copy of the file to my project I linked to the existing file (File -> New -> File -> Advanced -> "Link to file in the file system" -> c:\python26\scripts\twistd.py). This is key as you will use twistd.py to run your application from within Eclipse.

Now that your project is setup, create a new Run Configuration.

  1. Run -> Run Configurations
  2. Use the following values under the Main Tab
    • Name: Twisted (or whatever)
    • Project: MYPROJ
    • Main Module: ${workspace_loc:MYPROJ/twistd.py}
  3. Use the following values under the Arguments Tab
    • Program Arguments: -ny ${workspace_loc:MYPROJ/mytwistapp.tac}

And that's it! The key is importing twistd.py as the Main Module, which then allows the program arguments to be passed into twsttd.py, just as you would do from the command line.



来源:https://stackoverflow.com/questions/4794707/running-a-twisted-application-in-pydev

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!