12
12
from wolframclient .utils .decorators import cached_property , to_dict
13
13
from wolframclient .utils .functional import first
14
14
from wolframclient .utils .importutils import module_path
15
+
15
16
from wolframwebengine .server .app import create_session , create_view , is_wl_code
16
17
17
18
@@ -46,7 +47,7 @@ def add_arguments(self, parser):
46
47
default = 20 ,
47
48
help = "Startup timeout (in seconds) for kernels in the pool." ,
48
49
type = int ,
49
- metavar = "SECONDS"
50
+ metavar = "SECONDS" ,
50
51
)
51
52
parser .add_argument (
52
53
"--cached" ,
@@ -72,6 +73,14 @@ def add_arguments(self, parser):
72
73
choices = tuple (self .demo_choices .keys ()),
73
74
)
74
75
76
+ parser .add_argument (
77
+ "--client_max_size" ,
78
+ default = 10 ,
79
+ dest = "client_max_size" ,
80
+ help = "Maximum size of client uploads, in Mb" ,
81
+ type = float ,
82
+ )
83
+
75
84
def print_line (self , f = "" , s = "" ):
76
85
self .print (f .ljust (15 ), s )
77
86
@@ -95,29 +104,55 @@ def demo_choices(self):
95
104
def demo_path (self , * args ):
96
105
return module_path ("wolframwebengine" , "examples" , "demo" , * args )
97
106
98
- def handle (self , domain , port , path , kernel , poolsize , lazy , index , demo , initfile , startuptimeout , ** opts ):
107
+ def handle (
108
+ self ,
109
+ domain ,
110
+ port ,
111
+ path ,
112
+ kernel ,
113
+ poolsize ,
114
+ lazy ,
115
+ index ,
116
+ demo ,
117
+ initfile ,
118
+ startuptimeout ,
119
+ client_max_size ,
120
+ ** opts
121
+ ):
99
122
100
123
if demo is None or demo :
101
124
path = self .demo_path (self .demo_choices [demo ])
102
125
103
126
path = os .path .abspath (os .path .expanduser (path ))
104
127
128
+ client_max_size = int (client_max_size * (1024 ** 2 ))
129
+
105
130
try :
106
- session = create_session (kernel ,
107
- poolsize = poolsize , initfile = initfile ,
108
- STARTUP_TIMEOUT = startuptimeout
131
+ session = create_session (
132
+ kernel , poolsize = poolsize , initfile = initfile , STARTUP_TIMEOUT = startuptimeout
109
133
)
110
134
111
135
except WolframKernelException as e :
112
136
self .print (e )
113
137
self .print ("Use --help to display all available options." )
114
138
sys .exit (1 )
115
139
140
+ loop = asyncio .get_event_loop ()
141
+
116
142
async def main ():
117
143
118
144
view = create_view (session , path , index = index , ** opts )
119
145
120
- runner = self .ServerRunner (self .Server (view , access_log_class = self .AccessLogger ))
146
+ def request_factory (* args , ** opts ):
147
+ return web .BaseRequest (
148
+ * args , ** opts , client_max_size = client_max_size , loop = loop
149
+ )
150
+
151
+ runner = self .ServerRunner (
152
+ self .Server (
153
+ view , access_log_class = self .AccessLogger , request_factory = request_factory
154
+ )
155
+ )
121
156
await runner .setup ()
122
157
await self .TCPSite (runner , domain , port ).start ()
123
158
@@ -160,7 +195,6 @@ async def main():
160
195
while True :
161
196
await asyncio .sleep (3600 )
162
197
163
- loop = asyncio .get_event_loop ()
164
198
try :
165
199
loop .run_until_complete (main ())
166
200
except KeyboardInterrupt :
0 commit comments