5.2.2. vlcp.event.core


This document is generated from the source file.

View Source on GitHub

Created on 2015/6/12

exception vlcp.event.core.InterruptedBySignalException

In Python 3.x, we must raise an exception to interrupt the polling, or it will be automatically retried

class vlcp.event.core.PollEvent(*args, **kwargs)
exception vlcp.event.core.QuitException
class vlcp.event.core.Scheduler(polling=None, processevents=None, queuedefault=None, queuemax=None, defaultQueueClass=<class 'vlcp.event.pqueue.CBQueue.FifoQueue'>, defaultQueuePriority=0)

Event-driven scheduler

__init__(polling=None, processevents=None, queuedefault=None, queuemax=None, defaultQueueClass=<class 'vlcp.event.pqueue.CBQueue.FifoQueue'>, defaultQueuePriority=0)


  • polling – a polling source to retrieve events
  • processevents – max events processed before starting another poll
  • queuedefault – max length of default queue
  • queuemax – total max length of the event queue
  • defaultQueueClass – default queue class, see CBQueue
  • defaultQueuePriority – default queue priority, see CBQueue

Cancel the timer

Parameters:timer – the timer handle

Force send a new event to the main queue.


Unblock and ignore the matched events, if any.

main(installsignal=True, sendinit=True)

Start main loop

modifyPolling(fd, options)

modify options of a registered file descriptor


Send quit event to quit the main loop

register(matchers, runnable)

Register an iterator(runnable) to scheduler and wait for events

  • matchers – sequence of EventMatchers
  • runnable – an iterator that accept send method
  • daemon – if True, the runnable will be registered as a daemon.
registerPolling(fd, options=5, daemon=False)

register a polling file descriptor

  • fd – file descriptor or socket object
  • options – bit mask flags. Polling object should ignore the incompatible flag.

Send a new event to the main queue. If the queue or sub-queue is full, return a wait event

Returns:None if succeeded. Matcher for QueueCanWriteEvent if sub-queue is full.
setDaemon(runnable, isdaemon, noregister=False)

If a runnable is a daemon, it will not keep the main loop running. The main loop will end when all alived runnables are daemons.

setTimer(start, interval=None)

Generate a TimerEvent on specified time

  • start – offset for time from now (seconds), or datetime for a fixed time
  • interval – if not None, the timer is regenerated by interval seconds.

a timer handle to wait or cancel the timer


Call the func in core context (main loop).

func should like:

def syscall_sample(scheduler, processor):

where processor is a function which accept an event. When calling processor, scheduler directly process this event without sending it to queue.

An event matcher is returned to the caller, and the caller should wait for the event immediately to get the return value from the system call. The SyscallReturnEvent will have ‘retvalue’ as the return value, or ‘exception’ as the exception thrown: (type, value, traceback)

Parameters:func – syscall function
Returns:an event matcher to wait for the SyscallReturnEvent. If None is returned, a syscall is already scheduled; return to core context at first.
unregister(matchers, runnable)

Unregister an iterator(runnable) and stop waiting for events

  • matchers – sequence of EventMatchers
  • runnable – an iterator that accept send method
unregisterPolling(fd, daemon=False)

Unregister a polling file descriptor

Parameters:fd – file descriptor or socket object

Unregister all matches and detach the runnable. Automatically called when runnable returns StopIteration.


The next main loop will generate a SystemControlEvent(‘continue’), allowing time-consuming jobs to suspend and let other threads do their work


Pend this runnable to be wake up later

class vlcp.event.core.SyscallReturnEvent(*args, **kwargs)
class vlcp.event.core.SystemControlEvent(*args, **kwargs)
class vlcp.event.core.SystemControlLowPriorityEvent(*args, **kwargs)
class vlcp.event.core.TimerEvent(*args, **kwargs)

Clear a queue

vlcp.event.core.syscall_clearremovequeue(queue, index)

Clear the subqueue queue[index] and remove it from queue.


Directly process these events. This should never be used for normal events.


Directly process events from a generator function. This should never be used for normal events.

vlcp.event.core.syscall_removequeue(queue, index)

Remove subqueue queue[index] from queue.