<type>how-to</type>
<domain>install</domain>
<id>twisted</id>
<title>Using Wing with Twisted</title>
<date>$Date: 2006-12-28 17:21:05 -0500 (Thu, 28 Dec 2006) $</date>
<product>per+</product>
<summary>Learn how Wing can be used to speed up development and debugging of Python code written for the Twisted framework for network applications.</summary>

.. image:: /images/screenshots/wing7-screenshot-linen.png
  :alt: Wing Screen Shot
  :width: 574
  :height: 423
  :popup: 1

`Wing <https://wingware.com>`__ is a Python IDE that can be used to develop, test, and
debug Python code written for `Twisted <http://twistedmatrix.com/>`__. 

Two versions of Wing are appropriate for use with this document: Wing Pro is the
full-featured Python IDE for professional developers, and Wing Personal is a free
alternative with reduced feature set.

If you do not already have Wing installed, `download it now <https://wingware.com/downloads>`__.

This document describes how to configure Wing for Twisted. To get started using Wing as
your Python IDE, please refer to the tutorial in Wing's ``Help`` menu or read the
`Quickstart Guide <ref:howtos/quickstart>`__.

**Note:** This document is not being maintained and was last tested with Twisted
version 8.

Project Configuration
---------------------

To create a new project, use ``New Project`` in Wing's ``Project menu. Select the project
type ``Twisted`` and under ``Python Executable`` select ``Custom`` and then enter the full
path of the Python you plan to use with Twisted. You can determine the correct value
to use by executing the following commands interactively in Python.  If you are using
virtualenv, this will be the virtualenv's Python executable::

  import sys
  sys.executable

Press ``OK`` and then add the directory with your source code to the new project with
``Add Existing Directory`` in the ``Project`` menu.

Remote Development
..................

Wing Pro can work with Twisted code that is running on a remote host, VM, or container. To
do this, you need to be able to connect to the remote system with SSH. Then you can create
your project in the same way as above, using the ``Connect to Remote Host via SSH``
project type.  See `Remote Hosts <ref:proj/remote-hosts>`__ for more information on
remote development with Wing Pro.

Debug Configuration
-------------------

To debug Twisted code launched from within Wing, create a file with the following contents
and set it as your main entry point by adding it to your project and then using the ``Set
Main Entry Point`` item in the ``Debug`` menu::

    from twisted.scripts.twistd import run
    import os
    try:
        os.unlink('twistd.pid')
    except OSError:
        pass
    run()

Then go into the ``File Properties`` for this file (by right clicking on it) and set ``Run
Arguments`` as follows::

    -n -y filename.tac
  
The ``-n`` option tells Twisted not to daemonize, which would cause the debugger to fail
because sub-processes are not automatically debugged. The ``-y`` option serves to point
Twisted at your ``.tac`` file. Replace ``filename.tac`` in the above example with the
correct name of your file.

~~~if WINGPRO:
Wing Pro may be able to debug Twisted without the ``-n`` option, if you enable
``Debug Child Processes`` under the ``Debug/Execute`` tab of ``Project Properties``,
from the ``Project`` menu.
~~~

You can also launch Twisted code from outside of Wing as described in `Debugging
Externally Launched Code <ref:debug/debugging-externally-launched-code>`__ in the manual.

Related Documents
-----------------

For more information see:

* `Twisted home page <http://twistedmatrix.com/>`__, which provides links to documentation.

* `Quickstart Guide <ref:howtos/quickstart>`__ contains additional basic information
  about getting started with Wing.
  
* `Tutorial <ref:intro/tutorial>`__ provides a gentler introduction to Wing's features.

* `Wing Reference Manual <ref:manual>`__ documents Wing in detail.

