Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZEO
Commits
f96776b3
Commit
f96776b3
authored
Jul 16, 2016
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed load_before and preftech to use generators rather than callbacks
parent
db9d3da5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
21 deletions
+51
-21
src/ZEO/asyncio/client.py
src/ZEO/asyncio/client.py
+51
-21
No files found.
src/ZEO/asyncio/client.py
View file @
f96776b3
...
@@ -8,6 +8,7 @@ else:
...
@@ -8,6 +8,7 @@ else:
from
ZEO.Exceptions
import
ClientDisconnected
from
ZEO.Exceptions
import
ClientDisconnected
from
ZODB.ConflictResolution
import
ResolvedSerial
from
ZODB.ConflictResolution
import
ResolvedSerial
import
concurrent.futures
import
concurrent.futures
import
functools
import
logging
import
logging
import
random
import
random
import
threading
import
threading
...
@@ -27,6 +28,37 @@ Fallback = object()
...
@@ -27,6 +28,37 @@ Fallback = object()
local_random
=
random
.
Random
()
# use separate generator to facilitate tests
local_random
=
random
.
Random
()
# use separate generator to facilitate tests
def
future_generator
(
func
):
"""Decorates a generator that generates futures
"""
@
functools
.
wraps
(
func
)
def
call_generator
(
*
args
,
**
kw
):
gen
=
func
(
*
args
,
**
kw
)
try
:
f
=
next
(
gen
)
except
StopIteration
:
gen
.
close
()
else
:
def
store
(
gen
,
future
):
@
future
.
add_done_callback
def
_
(
future
):
try
:
try
:
result
=
future
.
result
()
except
Exception
as
exc
:
f
=
gen
.
throw
(
exc
)
else
:
f
=
gen
.
send
(
result
)
except
StopIteration
:
gen
.
close
()
else
:
store
(
gen
,
f
)
store
(
gen
,
f
)
return
call_generator
class
Protocol
(
base
.
Protocol
):
class
Protocol
(
base
.
Protocol
):
"""asyncio low-level ZEO client interface
"""asyncio low-level ZEO client interface
"""
"""
...
@@ -249,7 +281,7 @@ class Protocol(base.Protocol):
...
@@ -249,7 +281,7 @@ class Protocol(base.Protocol):
self
.
futures
[
message_id
]
=
future
self
.
futures
[
message_id
]
=
future
self
.
_write
(
self
.
_write
(
self
.
encode
(
message_id
,
False
,
'loadBefore'
,
(
oid
,
tid
)))
self
.
encode
(
message_id
,
False
,
'loadBefore'
,
(
oid
,
tid
)))
return
future
.
add_done_callback
return
future
# Methods called by the server.
# Methods called by the server.
# WARNING WARNING we can't call methods that call back to us
# WARNING WARNING we can't call methods that call back to us
...
@@ -525,30 +557,28 @@ class Client(object):
...
@@ -525,30 +557,28 @@ class Client(object):
# Special methods because they update the cache.
# Special methods because they update the cache.
@
future_generator
def
load_before_threadsafe
(
self
,
future
,
oid
,
tid
):
def
load_before_threadsafe
(
self
,
future
,
oid
,
tid
):
data
=
self
.
cache
.
loadBefore
(
oid
,
tid
)
data
=
self
.
cache
.
loadBefore
(
oid
,
tid
)
if
data
is
not
None
:
if
data
is
not
None
:
future
.
set_result
(
data
)
future
.
set_result
(
data
)
elif
self
.
ready
:
elif
self
.
ready
:
@
self
.
protocol
.
load_before
(
oid
,
tid
)
def
load_before
(
load_future
):
try
:
try
:
data
=
load_future
.
result
()
data
=
yield
self
.
protocol
.
load_before
(
oid
,
tid
)
except
Exception
as
exc
:
future
.
set_exception
(
exc
)
else
:
future
.
set_result
(
data
)
future
.
set_result
(
data
)
if
data
:
if
data
:
data
,
start
,
end
=
data
data
,
start
,
end
=
data
self
.
cache
.
store
(
oid
,
start
,
end
,
data
)
self
.
cache
.
store
(
oid
,
start
,
end
,
data
)
except
Exception
as
exc
:
future
.
set_exception
(
exc
)
else
:
else
:
self
.
_when_ready
(
self
.
load_before_threadsafe
,
future
,
oid
,
tid
)
self
.
_when_ready
(
self
.
load_before_threadsafe
,
future
,
oid
,
tid
)
@
future_generator
def
_prefetch
(
self
,
oid
,
tid
):
def
_prefetch
(
self
,
oid
,
tid
):
@
self
.
protocol
.
load_before
(
oid
,
tid
)
def
load_before
(
load_future
):
try
:
try
:
data
=
load_future
.
result
(
)
data
=
yield
self
.
protocol
.
load_before
(
oid
,
tid
)
if
data
:
if
data
:
data
,
start
,
end
=
data
data
,
start
,
end
=
data
self
.
cache
.
store
(
oid
,
start
,
end
,
data
)
self
.
cache
.
store
(
oid
,
start
,
end
,
data
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment