Databases and threading

Éloi Rivard <[email protected]> Tue, 19 Nov 2019 02:44:00 -0800 (PST)
Newsgroups gmane.comp.web.zope.zodb
Message-ID <[email protected]>
------=_Part_877_518719894.1574160240669
Content-Type: multipart/alternative; 
	boundary="----=_Part_878_1073719334.1574160240669"

------=_Part_878_1073719334.1574160240669
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hello, There are a few things I wonder about ZODB and concurrency, and I am=
=20
not sure of the answers the documentation gives.
The documentation states tha database connections, transactions managers=20
and transactions are not thread safe. It also states that we cannot share=
=20
databases between processes. But can we share databases an storages between=
=20
threads? Is this code safe?

import ZODB, threading
db =3D ZODB.DB(None)
def work():
    with db.transaction() as conn:
        do_stuff()

threading.Thread(target=3Dwork).start()
threading.Thread(target=3Dwork).start()

Thank you for your answers

=C3=89loi

--=20
You received this message because you are subscribed to the Google Groups "=
zodb" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/=
zodb/590aa292-4e00-4f26-94a0-8f02f36388fa%40googlegroups.com.

------=_Part_878_1073719334.1574160240669
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hello,
There are a few things I wonder about ZODB and concurrency, and I am not su=
re of the answers
the documentation gives.</div><div>The documentation states tha database co=
nnections, transactions managers and transactions are not thread safe. It a=
lso states that we cannot share databases between processes. But can we sha=
re databases an storages between threads? Is this code safe?<br></div><div>=
<br></div><div><div style=3D"background-color: rgb(250, 250, 250); border-c=
olor: rgb(187, 187, 187); border-style: solid; border-width: 1px; overflow-=
wrap: break-word; --darkreader-inline-bgcolor:#1a1b1c; --darkreader-inline-=
border-top:#414141; --darkreader-inline-border-right:#414141; --darkreader-=
inline-border-bottom:#414141; --darkreader-inline-border-left:#414141;" cla=
ss=3D"prettyprint" data-darkreader-inline-bgcolor=3D"" data-darkreader-inli=
ne-border-top=3D"" data-darkreader-inline-border-right=3D"" data-darkreader=
-inline-border-bottom=3D"" data-darkreader-inline-border-left=3D""><code cl=
ass=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">import</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> ZODB</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> threading<br>db </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> ZODB</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">DB</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">None</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">def</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> work</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">():</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">with</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> db</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">.</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">transaction</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">as</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> conn</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 do_stuff</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">()</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><b=
r>threading</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>.</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Thread</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">target</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">work</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">).</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">start</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br>threading</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">.</span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Thread</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">tar=
get</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">work</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">).</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">start</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span></div></code></div></div><div>=
<br></div><div>Thank you for your answers</div><div><br></div><div>=C3=89lo=
i<br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;zodb&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">zodb+unsubscri=
[email protected]</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/d/msgid/zodb/590aa292-4e00-4f26-94a0-8f02f36388fa%40googlegroups.com?utm=
_medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/zodb=
/590aa292-4e00-4f26-94a0-8f02f36388fa%40googlegroups.com</a>.<br />

------=_Part_878_1073719334.1574160240669--

------=_Part_877_518719894.1574160240669--