On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch" <de***@nospam.web.dewrote:
>Jean-Paul Calderone wrote:
>On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham <ph************@gmail.comwrote:
>>[snip]
How would one assign a unique ID to the root at that point?
Here's one way
class Sequence(Persistence): def __init__(self): self.current = 0
def next(self): self.current += 1 return self.current
ticketSequence = Sequence()
class Ticket(Persistence): def __init__(self): self.id = ticketSequence.next()
Be aware that this isn't working concurrently. Depending on your application, this can be mitigated using a simple threading.Lock.
ZODB has transactions. That's probably the best way to make this
code safe for concurrent use. A threading.Lock would make threaded
use safe, but wouldn't give you multiprocess concurrency safety.
Jean-Paul 3 1669
Jean-Paul Calderone schrieb:
On Thu, 14 Aug 2008 16:15:11 +0200, "Diez B. Roggisch"
<de***@nospam.web.dewrote:
>Jean-Paul Calderone wrote:
>>On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham <ph************@gmail.comwrote: [snip]
How would one assign a unique ID to the root at that point?
Here's one way
class Sequence(Persistence): def __init__(self): self.current = 0
def next(self): self.current += 1 return self.current
ticketSequence = Sequence()
class Ticket(Persistence): def __init__(self): self.id = ticketSequence.next()
Be aware that this isn't working concurrently. Depending on your application, this can be mitigated using a simple threading.Lock.
ZODB has transactions. That's probably the best way to make this
code safe for concurrent use.
But that's a great deal more complicated! It requires merging, and while
this of course is possible, you should have mentioned it because
otherwise the OP might run into problems.
Diez
Diez B. Roggisch wrote:
But that's a great deal more complicated! It requires merging, and while
this of course is possible, you should have mentioned it because
otherwise the OP might run into problems.
A lock doesn't do the job at all. ZODB supports clustering through ZEO.
Multiple ZEO clients can be attached to a single or more ZODB servers.
Any kind of thread based locking is local to each ZEO client.
You have to sync a sequence generator across multiple ZEO clients, hook
into the two phase commit protocol or use the conflict resolution hooks.
The problem is more complex than you think.
Christian
Le Thursday 14 August 2008 20:14:19 Christian Heimes, vous avez écrit*:
Diez B. Roggisch wrote:
But that's a great deal more complicated! It requires merging, and while
this of course is possible, you should have mentioned it because
otherwise the OP might run into problems.
A lock doesn't do the job at all. ZODB supports clustering through ZEO.
Multiple ZEO clients can be attached to a single or more ZODB servers.
Any kind of thread based locking is local to each ZEO client.
You have to sync a sequence generator across multiple ZEO clients, hook
into the two phase commit protocol or use the conflict resolution hooks.
You don't have too if you manage the conflict error anywhere else in the
program just manage the exception ConflictError and let the user retry later,
that will not happen that much on most application.
But,
The problem is more complex than you think.
Not that complex, strength of ZODB is right here, this entirely covered by the
introduction to zodb (ZODB/ZEO programming guide), see userdb and chatter
examples.
Christian
-- http://mail.python.org/mailman/listinfo/python-list
--
_____________
Maric Michaud This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul Rubin |
last post by:
I've started a few threads before on object persistence in medium to
high end server apps. This one is about low end apps, for example, a
simple cgi on a personal web site that might get a dozen...
|
by: ls |
last post by:
Hi All,
I looking for help with ZODB data export to text file. I have file
Data.fs (file becomes from Plone CMS) and I have to display content
structure, data like intro, body of article, etc...
|
by: Harald Armin Massa |
last post by:
Hello,
I am using ZODB "standalone" in version 3.3.1 within some application.
Now I learn that the 3.3.x branch of ZODB is "retired". No problem so
far, everything is running fine.
BUT......
|
by: Rene Pijlman |
last post by:
I have a productional Linux web server with a Python/Zope/Plone. Now I'd
like to install a non-Zope Python/ZODB application on the same server.
What is the recommended way of doing that?
Option...
|
by: vd12005 |
last post by:
Hello,
While playing to write an inverted index (see:
http://en.wikipedia.org/wiki/Inverted_index), i run out of memory with
a classic dict, (i have thousand of documents and millions of terms,...
|
by: Petra Chong |
last post by:
Hello all
I am using Python 2.3 and ZODB (without the rest of Zope) with the
following pattern:
* One process which writes stuff to a ZODB instance (call it test.db)
* Another process which...
|
by: teddysnips |
last post by:
SQL Server 2000 (DDL below)
If I try to run this code in QA:
SET IDENTITY_INSERT tblAdminUsers ON
INSERT INTO tblAdminUsers
(fldUserID,
fldUsername,
fldPassword,
fldFullname,
|
by: Aaron Watters |
last post by:
I've been poking around the world of object-relational
mappers and it inspired me to coin a corellary to the
the famous quote on regular expressions:
"You have objects and a database: that's 2...
|
by: Phillip B Oldham |
last post by:
Hi all. I'm playing with standalone ZODB at the moment trying to get a
better understanding of its use in applications. I come from a
PHP/MySQL background, and I'm taking my first steps with Python...
|
by: Jean-Paul Calderone |
last post by:
On Thu, 14 Aug 2008 05:22:35 -0700 (PDT), Phillip B Oldham <phillip.oldham@gmail.comwrote:
Here's one way
class Sequence(Persistence):
def __init__(self):
self.current = 0
def next(self):...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| | |