How are Plone BrowserView objects instantiated?

Hello best community in the world :wink:

I have a very elementary question about Plone.

When you access a Plone 5.2 website with an internet browser, . Is not a separate BrowserView object created and a corresponding thread started ? But how is it if you call the same Plone page from another internet browser window, is a new BrowserView object created and a new thread started ?

Or what is the scope of the BrowserView objects, singleton ?

I would be very happy about a nice explanation. ^^

Greetings :slight_smile:

An external (to the Zope/Plone core) component handles the use of threads. In a stock Plone setup, this component is waitress and it uses a thread pool. Requests are queued when the pools has no inactive threads.

BrowserViews are instantiated for each new request. Technically, they are adapters and each adaptation results in a new instance.

2 Likes

Hello, thank you for your reply:

But when accessing a Python object through the BrowserView, shouldn't the (Python-) object be Threadsafe ?

For example: If the (Python-) object is a singleton for example ?

The ZODB has separate object state versions for each connection (which usually means each thread) which contains the state at the time of the transaction start. Modifications are applied to this copy; on transaction commit, the modifications are made persistent -- provided there are no conflicts. Roughly speaking, this means that objects in the ZODB are thread safe.

Other objects (such as e.g. BrowserViews (or more general adapters) are transient): they live only in a single request. Usually, (if you do not pass them) they are visible only in a single request.

If you use other objects, you may need to ensure thread safety on your own.

1 Like

If you use other objects, you may need to ensure thread safety on your own.

Would a singleton that is threadsafe be useful ?

Can you maybe give a more detailed explanation about what you want to achieve? What is your usecase?