##// END OF EJS Templates
Initial refactor of task dependency system....
Initial refactor of task dependency system. We are thinking about refactoring the task dependency system. Currently is is based on engine properties and a function sent with each task. In this commit, I have added a TaskRejectError that tasks can raise to indicate that the engine doesn't have the required dependencies. For now I have not removed any of the old stuff, but I have added warnings that we might remove the older *_prop* methods in IMultiEngine. See this ticket for more info: https://bugs.launchpad.net/bugs/361419

File last commit:

r1853:b8f5152c
r1952:d68cab7f
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