Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyodide
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
Boxiang Sun
pyodide
Commits
20361551
Commit
20361551
authored
Sep 12, 2018
by
Michael Droettboom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Stream the data from the CGI script
parent
65817abc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
18 deletions
+32
-18
test/largish.json.cgi
test/largish.json.cgi
+32
-18
No files found.
test/largish.json.cgi
View file @
20361551
...
...
@@ -6,28 +6,42 @@ import sys
random
.
seed
(
0
)
print
(
"Content-Type: application/json"
)
print
()
columns
=
[
(
'column0'
,
lambda
:
'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
),
(
'column1'
,
lambda
:
random
.
choice
([
'notification-interval-longer'
,
'notification-interval-short'
,
'control'
])),
(
'column2'
,
lambda
:
random
.
choice
([
True
,
False
])),
(
'column3'
,
lambda
:
random
.
randint
(
0
,
4
)),
(
'column4'
,
lambda
:
random
.
randint
(
0
,
4
)),
(
'column5'
,
lambda
:
random
.
randint
(
0
,
4
)),
(
'column6'
,
lambda
:
random
.
randint
(
0
,
4
)),
(
'column7'
,
lambda
:
random
.
randint
(
0
,
4
))
(
'column0'
,
lambda
:
'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
),
(
'column1'
,
lambda
:
random
.
choice
([
'notification-interval-longer'
,
'notification-interval-short'
,
'control'
])),
(
'column2'
,
lambda
:
random
.
choice
([
True
,
False
])),
(
'column3'
,
lambda
:
random
.
randint
(
0
,
4
)),
(
'column4'
,
lambda
:
random
.
randint
(
0
,
4
)),
(
'column5'
,
lambda
:
random
.
randint
(
0
,
4
)),
(
'column6'
,
lambda
:
random
.
randint
(
0
,
4
)),
(
'column7'
,
lambda
:
random
.
randint
(
0
,
4
))
]
N_ROWS
=
91746
data
=
{}
N_ROWS
=
91746
# the output JSON size will be ~15 MB/10k rows
class
StreamDict
(
dict
):
"""
To serialize to JSON, we create an iterable object that inherits from a
known supported object type: dict.
"""
def
__init__
(
self
,
generator
):
self
.
generator
=
generator
def
items
(
self
):
for
i
in
range
(
N_ROWS
):
yield
i
,
self
.
generator
()
def
__len__
(
self
):
return
1
data
=
{}
for
name
,
generator
in
columns
:
column
=
{}
for
i
in
range
(
N_ROWS
):
column
[
str
(
i
)]
=
generator
()
data
[
name
]
=
column
data
[
name
]
=
StreamDict
(
generator
)
print
(
"Content-Type: application/json"
)
print
()
json
.
dump
(
data
,
sys
.
stdout
)
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