Ejemplo n.º 1
0
    def __init__(self, manager, info, name=""):
        self._manager = manager

        # Store info that defines the kernel
        self._originalInfo = KernelInfo(info)

        # Make a copy for the current version. This copy is re-created on
        # each restart
        self._info = ssdf.copy(self._originalInfo)

        # Store name (or should the name be defined in the info struct)
        self._name = name

        # Create context for the connection to the kernel and IDE's
        # This context is persistent (it stays as long as this KernelBroker
        # instance is alive).
        self._context = yoton.Context()
        self._kernelCon = None
        self._ctrl_broker = None

        # Create yoton-based timer
        self._timer = yoton.Timer(0.2, oneshot=False)
        self._timer.bind(self.mainLoopIter)

        # Kernel process and connection (these are replaced on restarting)
        self._reset()

        # For restarting after terminating
        self._pending_restart = None
Ejemplo n.º 2
0
# Create a context and a sub channel
ct2 = yoton.Context(verbose=verbosity)
sub = yoton.SubChannel(ct2, 'foo')

# Connect, set channel to event driven mode
ct2.connect('publichost:test')

# Create message handler 
def message_handler():
    message = sub.recv(False)
    if message:
        print(message)
        if message.lower() == 'stop':
            yoton.stop_event_loop()

# Bind handler to a timer
timer = yoton.Timer(0.1, False)
timer.bind(message_handler)
timer.start()


# Send messages
yoton.call_later(pub.send, 8, 'stop')
yoton.call_later(pub.send, 2, '2 seconds')
yoton.call_later(pub.send, 4, '4 seconds')
yoton.call_later(pub.send, 6, 'almost done')

# Enter event loop
yoton.start_event_loop()