Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:11:36+00:00 2026-06-11T05:11:36+00:00

Let’s say I have the following simple class: import cherrypy import os class test:

  • 0

Let’s say I have the following simple class:

import cherrypy
import os

class test:
  test_member = 0;
  def __init__(self):
    return
  def index(self):
    self.test_member = self.test_member + 1
    return str(self.test_member)
  index.exposed = True

conf = os.path.join(os.path.dirname(__file__), 'config.ini')

if __name__ == '__main__':
  # CherryPy always starts with app.root when trying to map request URIs
  # to objects, so we need to mount a request handler root. A request
  # to '/' will be mapped to HelloWorld().index().
  cherrypy.config.update({'server.socket_host': '0.0.0.0'})
  cherrypy.quickstart(test(), config=conf)
else:
  # This branch is for the test suite; you can ignore it.
  cherrypy.config.update({'server.socket_host': '0.0.0.0'})
  cherrypy.tree.mount(test(), config=conf)

So when I open my index page the first time I get back 1, the next time 2, then 3, 4, and so on. My questions are:

  • Are there any big dangers with this, particularly with threads and multiple people accessing the page at the same time?
  • Do I have to lock the member variable in some way each time it’s written to in order to prevent issues?
  • Does anything change if I’m using a none basic data type as a member (such as my own, complicated class) rather than something as simple as an integer?

I don’t totally understand how threading with CherryPy works, I suppose my concern in this simple example would be that on one thread the test_member could be equal to one thing, and when accessed from another thread it’d be something totally different. I apologize in advance if I’m missing something that’s well documented, but some googling didn’t really turn up what I was looking for. I understand for such a simple example there are a number of relatively easy paths that could solve potential problems here (keep the state of the variable in a database, or something along those lines), but that won’t work in my actual use case.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:11:38+00:00Added an answer on June 11, 2026 at 5:11 am

    There’s a danger there of lost updates. Just setting the value shouldn’t need to lock, since replacing an instance variable is atomic with respect to the GIL (assuming it doesn’t call any special methods, etc). But incrementing or using more complex variables will need different schemes to make them threadsafe.

    Shared access in CherryPy is generally no different than any other Python program. Rather than a long rehash of all those options here, it’s best to direct you to Thread Synchronization Mechanisms in Python As it mentions, replacing an instance variable is probably atomic with respect to the GIL and thereby thread-safe, but incrementing is not.

    CherryPy only adds some helpers in the opposite direction: when you don’t want to share: the cherrypy.request and cherrypy.response objects are newly created (and properly destroyed) for each request/response–feel free to stick data in cherrypy.request.foo if you want to keep it around for the duration of the request only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following classes : public class MyProductCode { private String
Let's say you have a class called Customer, which contains the following fields: UserName
Let me explain best with an example. Say you have node class that can
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say you have a class, with certain properties, and that you tried your
Let's say I have the following two lists of tuples myList = [(1, 7),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.