44
44
from urllib import error
45
45
import argparse
46
46
import client
47
- import multiprocessing
47
+ import os
48
48
import pickle
49
49
import sys
50
50
import logging
@@ -122,10 +122,6 @@ def main():
122
122
server_thread , timer_thread = None , None
123
123
try :
124
124
print ("You are running version {0} of ok.py" .format (client .__version__ ))
125
- if not args .local :
126
- timer_thread = multiprocessing .Process (target = network .server_timer ,
127
- args = ())
128
- timer_thread .start ()
129
125
130
126
cases = {case .type : case for case in core .get_testcases (config .cases )}
131
127
assignment = None
@@ -143,43 +139,22 @@ def main():
143
139
for p in protocol .get_protocols (config .protocols )]
144
140
145
141
messages = dict ()
146
- msg_queue = multiprocessing .Queue ()
147
- file_contents = []
142
+ msg_list = []
148
143
149
144
try :
150
145
with open (BACKUP_FILE , 'rb' ) as fp :
151
- file_contents = pickle .load (fp )
146
+ msg_list = pickle .load (fp )
152
147
log .info ('Loaded %d backed up messages from %s' ,
153
- len (file_contents ), BACKUP_FILE )
148
+ len (msg_list ), BACKUP_FILE )
154
149
except (IOError , EOFError ) as e :
155
150
log .info ('Error reading from ' + BACKUP_FILE \
156
151
+ ', assume nothing backed up' )
157
152
158
- for message in file_contents :
159
- msg_queue .put (message )
160
-
161
153
for proto in protocols :
162
154
log .info ('Execute %s.on_start()' , proto .name )
163
155
messages [proto .name ] = proto .on_start ()
164
156
messages ['timestamp' ] = str (datetime .now ())
165
157
166
- if not args .local :
167
- try :
168
- access_token = auth .authenticate (args .authenticate )
169
- log .info ('Authenticated with access token %s' , access_token )
170
-
171
- msg_queue .put (messages )
172
- staging_queue = multiprocessing .Queue ()
173
- interceptor = output .LogInterceptor ()
174
- server_thread = multiprocessing .Process (
175
- target = network .dump_to_server ,
176
- args = (access_token , msg_queue , assignment ['name' ],
177
- args .server , args .insecure , staging_queue ,
178
- client .__version__ , interceptor ))
179
- server_thread .start ()
180
- except error .URLError as ex :
181
- log .warning ('on_start messages not sent to server: %s' , str (e ))
182
-
183
158
interact_msg = {}
184
159
185
160
for proto in protocols :
@@ -191,36 +166,34 @@ def main():
191
166
# TODO(denero) Print server responses.
192
167
193
168
if not args .local :
194
- msg_queue . put (interact_msg )
169
+ msg_list . append (interact_msg )
195
170
196
- while timer_thread .is_alive ():
197
- pass
171
+ try :
172
+ access_token = auth .authenticate (args .authenticate )
173
+ log .info ('Authenticated with access token %s' , access_token )
198
174
199
- if not args .submit :
200
- server_thread .terminate ()
201
- else :
202
- server_thread .join ()
175
+ msg_list .append (messages )
176
+ print ("Attempting to send files to server..." )
177
+ network .dump_to_server (access_token , msg_list ,
178
+ assignment ['name' ], args .server , args .insecure ,
179
+ client .__version__ , log , send_all = args .submit )
203
180
204
- interceptor .dump_to_logger (log )
181
+ except error .URLError as ex :
182
+ log .warning ('on_start messages not sent to server: %s' , str (e ))
205
183
206
- dump_list = []
207
- while not msg_queue .empty ():
208
- dump_list .append (msg_queue .get_nowait ())
209
- while not staging_queue .empty ():
210
- dump_list .append (staging_queue .get_nowait ())
211
184
with open (BACKUP_FILE , 'wb' ) as fp :
212
- log .info ('Save %d unsent messages to %s' , len (dump_list ),
185
+ log .info ('Save %d unsent messages to %s' , len (msg_list ),
213
186
BACKUP_FILE )
214
- pickle .dump (dump_list , fp )
215
187
216
- if len (dump_list ) == 0 :
188
+ pickle .dump (msg_list , fp )
189
+ os .fsync (fp )
190
+
191
+ if len (msg_list ) == 0 :
217
192
print ("Server submission successful" )
218
193
219
194
except KeyboardInterrupt :
220
- if timer_thread :
221
- timer_thread .terminate ()
222
- if server_thread :
223
- server_thread .terminate ()
195
+ print ("Quitting ok." )
196
+
224
197
finally :
225
198
if assignment :
226
199
log .info ('Dump tests for %s to %s' , assignment ['name' ], args .tests )
0 commit comments