# Path: tornado/ioloop.py
# class IOLoop(object):
# class _Timeout(object):
# class PeriodicCallback(object):
# class _EPoll(object):
# class _KQueue(object):
# class _Select(object):
#     _EPOLLIN = 0x001
#     _EPOLLPRI = 0x002
#     _EPOLLOUT = 0x004
#     _EPOLLERR = 0x008
#     _EPOLLHUP = 0x010
#     _EPOLLRDHUP = 0x2000
#     _EPOLLONESHOT = (1 << 30)
#     _EPOLLET = (1 << 31)
#     NONE = 0
#     READ = _EPOLLIN
#     WRITE = _EPOLLOUT
#     ERROR = _EPOLLERR | _EPOLLHUP | _EPOLLRDHUP
#     _EPOLL_CTL_ADD = 1
#     _EPOLL_CTL_DEL = 2
#     _EPOLL_CTL_MOD = 3
#     def __init__(self, impl=None):
#     def instance():
#     def initialized():
#     def install(self):
#     def close(self, all_fds=False):
#     def add_handler(self, fd, handler, events):
#     def update_handler(self, fd, events):
#     def remove_handler(self, fd):
#     def set_blocking_signal_threshold(self, seconds, action):
#     def set_blocking_log_threshold(self, seconds):
#     def log_stack(self, signal, frame):
#     def start(self):
#     def stop(self):
#     def running(self):
#     def add_timeout(self, deadline, callback):
#     def remove_timeout(self, timeout):
#     def add_callback(self, callback):
#     def _run_callback(self, callback):
#     def handle_callback_exception(self, callback):
#     def __init__(self, deadline, callback):
#     def timedelta_to_seconds(td):
#     def __lt__(self, other):
#     def __le__(self, other):
#     def __init__(self, callback, callback_time, io_loop=None):
#     def start(self):
#     def stop(self):
#     def _run(self):
#     def _schedule_next(self):
#     def __init__(self):
#     def fileno(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def poll(self, timeout):
#     def __init__(self):
#     def fileno(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def _control(self, fd, events, flags):
#     def poll(self, timeout):
#     def __init__(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def poll(self, timeout):


import errno
import logging
import os
import sys
import time
    import multiprocessing # Python 2.6+
    import random
from binascii import hexlify
from tornado import ioloop
_task_id = None

def fork_processes(num_processes, max_restarts=100):
    """Starts multiple worker processes.

    If ``num_processes`` is None or <= 0, we detect the number of cores
    available on this machine and fork that number of child
    processes. If ``num_processes`` is given and > 0, we fork that
    specific number of sub-processes.

    Since we use processes and not threads, there is no shared memory
    between any server code.

    Note that multiple processes are not compatible with the autoreload
    module (or the debug=True option to `tornado.web.Application`).
    When using multiple processes, no IOLoops can be created or
    referenced until after the call to ``fork_processes``.

    In each child process, ``fork_processes`` returns its *task id*, a
    number between 0 and ``num_processes``.  Processes that exit
    abnormally (due to a signal or non-zero exit status) are restarted
    with the same id (up to ``max_restarts`` times).  In the parent
    process, ``fork_processes`` returns None if all child processes
    have exited normally, but will otherwise only exit by throwing an
    exception.
    """
    global _task_id
    assert _task_id is None
    if num_processes is None or num_processes <= 0:
        num_processes = cpu_count()

# Path: tornado/ioloop.py
# class IOLoop(object):
# class _Timeout(object):
# class PeriodicCallback(object):
# class _EPoll(object):
# class _KQueue(object):
# class _Select(object):
#     _EPOLLIN = 0x001
#     _EPOLLPRI = 0x002
#     _EPOLLOUT = 0x004
#     _EPOLLERR = 0x008
#     _EPOLLHUP = 0x010
#     _EPOLLRDHUP = 0x2000
#     _EPOLLONESHOT = (1 << 30)
#     _EPOLLET = (1 << 31)
#     NONE = 0
#     READ = _EPOLLIN
#     WRITE = _EPOLLOUT
#     ERROR = _EPOLLERR | _EPOLLHUP | _EPOLLRDHUP
#     _EPOLL_CTL_ADD = 1
#     _EPOLL_CTL_DEL = 2
#     _EPOLL_CTL_MOD = 3
#     def __init__(self, impl=None):
#     def instance():
#     def initialized():
#     def install(self):
#     def close(self, all_fds=False):
#     def add_handler(self, fd, handler, events):
#     def update_handler(self, fd, events):
#     def remove_handler(self, fd):
#     def set_blocking_signal_threshold(self, seconds, action):
#     def set_blocking_log_threshold(self, seconds):
#     def log_stack(self, signal, frame):
#     def start(self):
#     def stop(self):
#     def running(self):
#     def add_timeout(self, deadline, callback):
#     def remove_timeout(self, timeout):
#     def add_callback(self, callback):
#     def _run_callback(self, callback):
#     def handle_callback_exception(self, callback):
#     def __init__(self, deadline, callback):
#     def timedelta_to_seconds(td):
#     def __lt__(self, other):
#     def __le__(self, other):
#     def __init__(self, callback, callback_time, io_loop=None):
#     def start(self):
#     def stop(self):
#     def _run(self):
#     def _schedule_next(self):
#     def __init__(self):
#     def fileno(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def poll(self, timeout):
#     def __init__(self):
#     def fileno(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def _control(self, fd, events, flags):
#     def poll(self, timeout):
#     def __init__(self):
#     def close(self):
#     def register(self, fd, events):
#     def modify(self, fd, events):
#     def unregister(self, fd):
#     def poll(self, timeout):


# Path: tornado/process.py
import errno
import logging
import os
import sys
import time
    import multiprocessing # Python 2.6+
    import random
from binascii import hexlify
from tornado import ioloop

_task_id = None

def fork_processes(num_processes, max_restarts=100):
    """Starts multiple worker processes.

    If ``num_processes`` is None or <= 0, we detect the number of cores
    available on this machine and fork that number of child
    processes. If ``num_processes`` is given and > 0, we fork that
    specific number of sub-processes.

    Since we use processes and not threads, there is no shared memory
    between any server code.

    Note that multiple processes are not compatible with the autoreload
    module (or the debug=True option to `tornado.web.Application`).
    When using multiple processes, no IOLoops can be created or
    referenced until after the call to ``fork_processes``.

    In each child process, ``fork_processes`` returns its *task id*, a
    number between 0 and ``num_processes``.  Processes that exit
    abnormally (due to a signal or non-zero exit status) are restarted
    with the same id (up to ``max_restarts`` times).  In the parent
    process, ``fork_processes`` returns None if all child processes
    have exited normally, but will otherwise only exit by throwing an
    exception.
    """
    global _task_id
    assert _task_id is None
    if num_processes is None or num_processes <= 0:
        num_processes = cpu_count()

    if ioloop.IOLoop.initialized():