##// END OF EJS Templates
launcher updates for PBS
launcher updates for PBS

File last commit:

r3642:a0bfb1f7
r3645:8a8cbf5d
Show More
entry_point.py
119 lines | 3.5 KiB | text/x-python | PythonLexer
MinRK
added zmq controller/engine entry points
r3550 """ Defines helper functions for creating kernel entry points and process
launchers.
MinRK
Refactor newparallel to use Config system...
r3604
************
NOTE: Most of this module has been deprecated by moving to Configurables
************
MinRK
added zmq controller/engine entry points
r3550 """
# Standard library imports.
import atexit
MinRK
resort imports in a cleaner order
r3631 import logging
MinRK
added zmq controller/engine entry points
r3550 import os
MinRK
added exec_key and fixed client.shutdown
r3575 import stat
MinRK
added zmq controller/engine entry points
r3550 import socket
MinRK
resort imports in a cleaner order
r3631 import sys
MinRK
Moved parallel test files to parallel subpackages...
r3573 from signal import signal, SIGINT, SIGABRT, SIGTERM
MinRK
resort imports in a cleaner order
r3631 from subprocess import Popen, PIPE
MinRK
Moved parallel test files to parallel subpackages...
r3573 try:
from signal import SIGKILL
except ImportError:
SIGKILL=None
MinRK
added zmq controller/engine entry points
r3550
# System library imports.
import zmq
from zmq.log import handlers
MinRK
eliminate relative imports
r3642
MinRK
added zmq controller/engine entry points
r3550 # Local imports.
from IPython.core.ultratb import FormattedTB
from IPython.external.argparse import ArgumentParser
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 from IPython.zmq.log import EnginePUBHandler
MinRK
added zmq controller/engine entry points
r3550
MinRK
Refactor newparallel to use Config system...
r3604 _random_ports = set()
MinRK
added zmq controller/engine entry points
r3550 def select_random_ports(n):
MinRK
added exec_key and fixed client.shutdown
r3575 """Selects and return n random ports that are available."""
MinRK
added zmq controller/engine entry points
r3550 ports = []
for i in xrange(n):
sock = socket.socket()
sock.bind(('', 0))
MinRK
Refactor newparallel to use Config system...
r3604 while sock.getsockname()[1] in _random_ports:
sock.close()
sock = socket.socket()
sock.bind(('', 0))
MinRK
added zmq controller/engine entry points
r3550 ports.append(sock)
for i, sock in enumerate(ports):
port = sock.getsockname()[1]
sock.close()
ports[i] = port
MinRK
Refactor newparallel to use Config system...
r3604 _random_ports.add(port)
MinRK
added zmq controller/engine entry points
r3550 return ports
MinRK
added simple cluster entry point
r3552
MinRK
Moved parallel test files to parallel subpackages...
r3573 def signal_children(children):
MinRK
added exec_key and fixed client.shutdown
r3575 """Relay interupt/term signals to children, for more solid process cleanup."""
MinRK
Moved parallel test files to parallel subpackages...
r3573 def terminate_children(sig, frame):
MinRK
Refactor newparallel to use Config system...
r3604 logging.critical("Got signal %i, terminating children..."%sig)
MinRK
Moved parallel test files to parallel subpackages...
r3573 for child in children:
child.terminate()
MinRK
Refactor newparallel to use Config system...
r3604
sys.exit(sig != SIGINT)
MinRK
Moved parallel test files to parallel subpackages...
r3573 # sys.exit(sig)
for sig in (SIGINT, SIGABRT, SIGTERM):
signal(sig, terminate_children)
MinRK
added zmq controller/engine entry points
r3550
MinRK
added exec_key and fixed client.shutdown
r3575 def generate_exec_key(keyfile):
import uuid
newkey = str(uuid.uuid4())
with open(keyfile, 'w') as f:
# f.write('ipython-key ')
MinRK
Refactor newparallel to use Config system...
r3604 f.write(newkey+'\n')
MinRK
added exec_key and fixed client.shutdown
r3575 # set user-only RW permissions (0600)
# this will have no effect on Windows
os.chmod(keyfile, stat.S_IRUSR|stat.S_IWUSR)
MinRK
added zmq controller/engine entry points
r3550
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 def integer_loglevel(loglevel):
MinRK
propagate iopub to clients
r3602 try:
loglevel = int(loglevel)
except ValueError:
if isinstance(loglevel, str):
loglevel = getattr(logging, loglevel)
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 return loglevel
MinRK
rework logging connections
r3610 def connect_logger(logname, context, iface, root="ip", loglevel=logging.DEBUG):
logger = logging.getLogger(logname)
MinRK
Refactor newparallel to use Config system...
r3604 if any([isinstance(h, handlers.PUBHandler) for h in logger.handlers]):
# don't add a second PUBHandler
return
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 loglevel = integer_loglevel(loglevel)
MinRK
added zmq controller/engine entry points
r3550 lsock = context.socket(zmq.PUB)
lsock.connect(iface)
handler = handlers.PUBHandler(lsock)
handler.setLevel(loglevel)
handler.root_topic = root
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 logger.addHandler(handler)
logger.setLevel(loglevel)
def connect_engine_logger(context, iface, engine, loglevel=logging.DEBUG):
logger = logging.getLogger()
MinRK
Refactor newparallel to use Config system...
r3604 if any([isinstance(h, handlers.PUBHandler) for h in logger.handlers]):
# don't add a second PUBHandler
return
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 loglevel = integer_loglevel(loglevel)
lsock = context.socket(zmq.PUB)
lsock.connect(iface)
handler = EnginePUBHandler(engine, lsock)
handler.setLevel(loglevel)
logger.addHandler(handler)
logger.setLevel(loglevel)
MinRK
rework logging connections
r3610 def local_logger(logname, loglevel=logging.DEBUG):
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 loglevel = integer_loglevel(loglevel)
MinRK
rework logging connections
r3610 logger = logging.getLogger(logname)
MinRK
Refactor newparallel to use Config system...
r3604 if any([isinstance(h, logging.StreamHandler) for h in logger.handlers]):
# don't add a second StreamHandler
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 return
handler = logging.StreamHandler()
handler.setLevel(loglevel)
MinRK
added zmq controller/engine entry points
r3550 logger.addHandler(handler)
MinRK
improved logging + Hub,Engine,Scheduler are Configurable
r3603 logger.setLevel(loglevel)