Plugins
An application requires functions outside the request cycle to run background tasks and manage various connections. Plugins closely work with the CherryPy engine and extend it to perform various other operations. Plugins can be implemented using the cherrypy.process.plugins module. Some of the commonly used plugins are:
-
cherrypy.process.plugins.monitor: It is a Web Site Process bus listener to periodically run a callback in its thread.
-
cherrypy.process.plugins.Autoreloader: It restarts the process if any changes in files are detected. By default, it monitors all imported modules.
-
cherrypy.process.plugin.BackgroundTask: It is a subclass of threading.Thread that runs repeating tasks.
- cherrypy.process.plugins.ThreadManager: It manages all HTTP request threads.
Tools
It is a CherryPy mechanism that helps execute a variety of requests. It is typically a piece of code that runs to perform additional work as per the requests received. They can be used as a callable in any function whenever needed. Tools can also be used as decorators to configure page handlers in CherrPy. Built-in tools are either modules or instances of the tools.Tool class. Basic Authentication and caching tools are the most commonly used tools in CherryPy.
Frequently Asked Questions
What is the function of the CherrPy engine?
The CherryPy engine handles the creation and management of requests, responses and events. It also controls and manages all CherryPy objects.
What are the three main components of CherryPy?
The CherryPy engine handles events and controls process setup. The CherryPy server configures the HTTP server. CherryPy tools is a toolbox that helps execute HTTP requests.
What are the key advantages of using CherryPy?
CherryPy is simple and easily adjustable. Object-oriented concepts like inheritance, data abstraction and encapsulation can be implemented quickly. CherryPy has a web server of its own and is self-contained. This helps with fast deployments of applications.
Conclusion
This blog discusses organising code in CherryPy. It explains the three main mechanisms: dispatchers, plugins and tools. Check out our articles on JavaScript, CSS and images in CherryPy, PyTest and code coverage in CherryPy and REST with CherryPy. Explore our Library on Coding Ninjas Studio to gain knowledge on Data Structures and Algorithms, Machine Learning, Deep Learning, Cloud Computing and many more! Test your coding skills by solving our test series and participating in the contests hosted on Coding Ninjas Studio!
Looking for questions from tech giants like Amazon, Microsoft, Uber, etc.? Look at the problems, interview experiences, and interview bundle for placement preparations. Upvote our blogs if you find them insightful and engaging! Happy Coding!
