5.2.2. vlcp.event.core

Note

This document is generated from the source file.

View Source on GitHub

Created on 2015/6/12

author:hubo
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)

Constructor

Parameters:
  • 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
cancelTimer(timer)

Cancel the timer

Parameters:timer – the timer handle
emergesend(event)

Force send a new event to the main queue.

ignore(matcher)

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

quit(daemononly=False)

Send quit event to quit the main loop

register(matchers, runnable)

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

Parameters:
  • 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

Parameters:
  • fd – file descriptor or socket object
  • options – bit mask flags. Polling object should ignore the incompatible flag.
send(event)

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

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

a timer handle to wait or cancel the timer

syscall(func)

Call the func in core context (main loop).

func should like:

def syscall_sample(scheduler, processor):
    something...

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

Parameters:
  • 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
unregisterall(runnable)

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

wantContinue()

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

yield_(runnable)

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)
vlcp.event.core.syscall_clearqueue(queue)

Clear a queue

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

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

vlcp.event.core.syscall_direct(*events)

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

vlcp.event.core.syscall_generator(generator)

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.