##// END OF EJS Templates
Update copyright/author statements....
Update copyright/author statements. - Updated copyright statements to use the new form: # Copyright (C) 2008-2009 The IPython Development Team I left the old notices in place (just updating the year in some cases), because as far as I know, old copyright statements are not meant to be retroactively modified. - Also, on most files, replaced __author__ marks with an 'Authors' section in the module docstring. This reduces top-level code in the module, while ensuring that the Author(s) get properly acknowledged in auto-generated API docs (sphinx doesn't read __author__ marks, but it will include the module docstring). I only left a few in place for very old files that we ship externally, and for those by Laurent: he had his authorship mark both in the docstring and in __author__ variables, so I think out of courtesy it would be better to ask him about it on the list. All the others were I found regular __author__ variables, I moved them to the main docstring.

File last commit:

r1853:b8f5152c
r1875:bba7e571
Show More
shellglobals.py
101 lines | 3.5 KiB | text/x-python | PythonLexer
"""Some globals used by the main Shell classes.
"""
#-----------------------------------------------------------------------------
# Module imports
#-----------------------------------------------------------------------------
# stdlib
import inspect
import thread
try:
import ctypes
HAS_CTYPES = True
except ImportError:
HAS_CTYPES = False
# our own
from IPython.genutils import Term,warn,error,flag_calls, ask_yes_no
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
# global flag to pass around information about Ctrl-C without exceptions
KBINT = False
# global flag to turn on/off Tk support.
USE_TK = False
# ID for the main thread, used for cross-thread exceptions
MAIN_THREAD_ID = thread.get_ident()
# Tag when runcode() is active, for exception handling
CODE_RUN = None
#-----------------------------------------------------------------------------
# This class is trivial now, but I want to have it in to publish a clean
# interface. Later when the internals are reorganized, code that uses this
# shouldn't have to change.
if HAS_CTYPES:
# Add async exception support. Trick taken from:
# http://sebulba.wikispaces.com/recipe+thread2
def _async_raise(tid, exctype):
"""raises the exception, performs cleanup if needed"""
if not inspect.isclass(exctype):
raise TypeError("Only types can be raised (not instances)")
res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid,
ctypes.py_object(exctype))
if res == 0:
raise ValueError("invalid thread id")
elif res != 1:
# """if it returns a number greater than one, you're in trouble,
# and you should call it again with exc=NULL to revert the effect"""
ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, 0)
raise SystemError("PyThreadState_SetAsyncExc failed")
def sigint_handler (signum,stack_frame):
"""Sigint handler for threaded apps.
This is a horrible hack to pass information about SIGINT _without_
using exceptions, since I haven't been able to properly manage
cross-thread exceptions in GTK/WX. In fact, I don't think it can be
done (or at least that's my understanding from a c.l.py thread where
this was discussed)."""
global KBINT
if CODE_RUN:
_async_raise(MAIN_THREAD_ID,KeyboardInterrupt)
else:
KBINT = True
print '\nKeyboardInterrupt - Press <Enter> to continue.',
Term.cout.flush()
else:
def sigint_handler (signum,stack_frame):
"""Sigint handler for threaded apps.
This is a horrible hack to pass information about SIGINT _without_
using exceptions, since I haven't been able to properly manage
cross-thread exceptions in GTK/WX. In fact, I don't think it can be
done (or at least that's my understanding from a c.l.py thread where
this was discussed)."""
global KBINT
print '\nKeyboardInterrupt - Press <Enter> to continue.',
Term.cout.flush()
# Set global flag so that runsource can know that Ctrl-C was hit
KBINT = True
def run_in_frontend(src):
""" Check if source snippet can be run in the REPL thread, as opposed to
GUI mainloop (to prevent unnecessary hanging of mainloop).
"""
if src.startswith('_ip.system(') and not '\n' in src:
return True
return False