[wingide-users] Conditionally importing modules when Wing is not active/running

Wingware Support support at wingware.com
Mon Feb 25 13:28:07 MST 2008


Tony Cappellini wrote:
> in my project files, but also want to conditionally import psyco when
> I'm not running Wing.

My suggestion would be:

if __debug__:
   try:
     import wingdbstub
   except ImportError:
     wingdbstub = None
else:
   import psyco

The -O command line flag turns __debug__ on and off.  If you don't like 
-O, this may work:

try:
   import wingdbstub
except ImportError:
   wingdbstub = None
def IsWingActive():
   if wingdbstub is None or wingdbstub.debugger is None:
     return False
   else: # One could also test to see if a client IDE process is connected
     return True

if not IsWingActive():
   import psyco

John



More information about the wingide-users mailing list