[ Pobierz całość w formacie PDF ]

thread to call execv.
start()
Start all services.
start_with_callback(func, args=None, kwargs=None)
Start  func in a new thread T, then start self (and return T).
stop()
Stop all services.
subscribe(channel, callback, priority=None)
Add the given callback at the given channel (if not present).
unsubscribe(channel, callback)
Discard the given callback (if present).
wait(state, interval=0.1, channel=None)
Poll for the given state(s) at intervals; publish to channel.
7.14.4 cherrypy.process.plugins Engine Plugins
Site services for use with a Web Site Process Bus.
Classes
classcherrypy.process.plugins.SimplePlugin(bus)
Plugin base class which auto-subscribes methods for known channels.
bus= None
ABus, usually cherrypy.engine.
subscribe()
Register this object as a (multi-channel) listener on the bus.
unsubscribe()
Unregister this object as a listener on the bus.
classcherrypy.process.plugins.ThreadManager(bus)
Bases:cherrypy.process.plugins.SimplePlugin
Manager for HTTP request threads.
If you have control over thread creation and destruction, publish to the  acquire_thread and  release_thread
channels (for each thread). This will register/unregister the current thread and publish to  start_thread and
 stop_thread listeners in the bus as needed.
154 Chapter 7. Reference Manual
CherryPy Documentation, Release 3.2.4
If threads are created and destroyed by code you do not control (e.g., Apache), then, at the beginning of every
HTTP request, publish to  acquire_thread only. You should not publish to  release_thread in this case, since
you do not know whether the thread will be re-used or not. The bus will call  stop_thread listeners for you
when it stops.
acquire_thread()
Run  start_thread listeners for the current thread.
If the current thread has already been seen, any  start_thread listeners will not be run again.
graceful()
Release all threads and run all  stop_thread listeners.
release_thread()
Release the current thread and run  stop_thread listeners.
stop()
Release all threads and run all  stop_thread listeners.
threads= None
A map of {thread ident: index number} pairs.
Monitors
classcherrypy.process.plugins.BackgroundTask(interval, function, args=[], kwargs={},
bus=None)
A subclass of threading.Thread whose run() method repeats.
Use this class for most repeating tasks. It uses time.sleep() to wait for each interval, which isn t very responsive;
that is, even if you call self.cancel(), you ll have to wait until the sleep() call finishes before the thread stops. To
compensate, it defaults to being daemonic, which means it won t delay stopping the whole process.
classcherrypy.process.plugins.PerpetualTimer(*args, **kwargs)
A responsive subclass of threading.Timer whose run() method repeats.
Use this timer only when you really need a very interruptible timer; this checks its  finished condition up to 20
times a second, which can results in pretty high CPU usage
classcherrypy.process.plugins.Monitor(bus, callback, frequency=60, name=None)
Bases:cherrypy.process.plugins.SimplePlugin
WSPBus listener to periodically run a callback in its own thread.
callback= None
The function to call at intervals.
frequency= 60
The time in seconds between callback runs.
graceful()
Stop the callback s background task thread and restart it.
start()
Start our callback in its own background thread.
stop()
Stop our callback s background task thread.
thread= None
ABackgroundTaskthread.
7.14. cherrypy.process 155
CherryPy Documentation, Release 3.2.4
classcherrypy.process.plugins.Autoreloader(bus, frequency=1, match= .* )
Bases:cherrypy.process.plugins.Monitor
Monitor which re-executes the process when files change.
This plugin restarts the process (viaos.execv()) if any of the files it monitors change (or is deleted).
By default, the autoreloader monitors all imported modules; you can add to the set by adding to
autoreload.files:
cherrypy.engine.autoreload.files.add(myFile)
If there are imported files you do not wish to monitor, you can adjust thematchattribute, a regular expression.
For example, to stop monitoring cherrypy itself:
cherrypy.engine.autoreload.match = r ^(?!cherrypy).+
Like allMonitorplugins, the autoreload plugin takes afrequencyargument. The default is 1 second; that
is, the autoreloader will examine files once each second.
files= None
The set of files to poll for modifications.
frequency= 1
The interval in seconds at which to poll for modified files.
graceful()
Stop the callback s background task thread and restart it.
match=  .*
A regular expression by which to match filenames.
run()
Reload the process if registered files have been modified.
start()
Start our own background task thread for self.run.
stop()
Stop our callback s background task thread.
subscribe()
Register this object as a (multi-channel) listener on the bus.
sysfiles()
Return a Set of sys.modules filenames to monitor.
unsubscribe()
Unregister this object as a listener on the bus.
Other Plugins
Handling Signals
SignalHandler This Engine Plugin is instantiated automatically ascherrypy.engine.signal_handler.
However, it is only subscribed automatically bycherrypy.quickstart(). So if you want signal handling and
you re calling:
tree.mount(); engine.start(); engine.block()
on your own, be sure to add:
156 Chapter 7. Reference Manual
CherryPy Documentation, Release 3.2.4
if hasattr(cherrypy.engine,  signal_handler ):
cherrypy.engine.signal_handler.subscribe()
classcherrypy.process.plugins.SignalHandler(bus)
Register bus channels (and listeners) for system signals.
You can modify what signals your application listens for, and what it does when it receives signals, by modifying
SignalHandler.handlers, a dict of {signal name: callback} pairs. The default set is:
handlers = { SIGTERM : self.bus.exit,
 SIGHUP : self.handle_SIGHUP,
 SIGUSR1 : self.bus.graceful,
}
TheSignalHandler.handle_SIGHUP ()method callsbus.restart()if the process is daemo-
nized, butbus.exit()if the process is attached to a TTY. This is because Unix window managers tend
to send SIGHUP to terminal windows when the user closes them.
Feel free to add signals which are not available on every platform. TheSignalHandlerwill ignore errors
raised from attempting to register handlers for unknown signals.
handle_SIGHUP()
Restart if daemonized, else exit.
handlers= {}
A map from signal names (e.g.  SIGTERM ) to handlers (e.g. bus.exit).
set_handler(signal, listener=None)
Subscribe a handler for the given signal (number or name).
If the optional  listener argument is provided, it will be subscribed as a listener for the given signal s
channel.
If the given signal name or number is not available on the current platform, ValueError is raised.
signals= {1:  SIGHUP , 2:  SIGINT , 3:  SIGQUIT , 4:  SIGILL , 5:  SIGTRAP , 6:  SIGABRT , 7:  SIGBUS , 8:  SI
A map from signal numbers to names.
subscribe()
Subscribe self.handlers to signals.
unsubscribe()
Unsubscribe self.handlers from signals.
Windows Console Events Microsoft Windows uses console events to communicate some signals, like Ctrl-
C. When deploying CherryPy on Windows platforms, you should obtain the Python for Windows Exten-
sions; once you have them installed, CherryPy will handle Ctrl-C and other console events (CTRL_C_EVENT, [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • apsys.pev.pl