44from concurrent .futures import ProcessPoolExecutor
55
66sio = socketio .AsyncServer (async_mode = 'aiohttp' ,
7- cors_allowed_origins = [
8- 'http://localhost:8080' , 'http://localhost:8081' , 'https://data.syn.bike' ],
9- max_http_buffer_size = 1e9 , ping_timeout = 10 )
10- app = web .Application (client_max_size = 1e10 , debug = True )
7+ cors_allowed_origins = ['http://localhost:8080' ,
8+ 'http://localhost:8081' ,
9+ 'https://data' ],
10+ ping_timeout = 10 )
11+ app = web .Application ()
1112sio .attach (app )
1213
1314import json
@@ -100,8 +101,6 @@ async def save_file(sid, data):
100101 if data ['stage' ] == 'end' :
101102 print ('End file stream' )
102103 with open (filename , 'rb' ) as file :
103- # print(hashlib.sha1(file.read()).hexdigest())
104- # print(data['checksum'])
105104 if hashlib .sha1 (file .read ()).hexdigest () == data ['checksum' ]:
106105 print ('Is good file.' )
107106 await sio .emit ('file_loaded' , {"valid" : True })
@@ -115,8 +114,7 @@ async def save_file(sid, data):
115114
116115@sio .on ('close' )
117116def close_connection (sid ):
118- print ('Closed' )
119- print (sid )
117+ print (f'Connection Closed with { sid } ' )
120118
121119
122120def delete_file (filename , sid ):
@@ -136,12 +134,12 @@ def close_connection(sid):
136134 """
137135
138136 Timer (30 , delete_file , [secure_filename (sid + '.csv' ), sid ]).start ()
139- print ('disconnect ' )
137+ print ('Disconnection detected. ' )
140138
141139
142140@sio .on ('connect' )
143141def open_connection (sid , data ):
144- print ('connected' )
142+ print ('Client connected. ' )
145143 return True
146144
147145
@@ -152,7 +150,7 @@ def open_connection(sid, data):
152150 and rename if needed. This avoids the need to resend large files for
153151 short term disconnects.
154152 """
155- print ('RECONNECTION ' )
153+ print ('Reconnect detected. ' )
156154 new_filename = secure_filename (sid + '.csv' )
157155 old_filename = secure_filename (data ['id' ] + '.csv' )
158156
@@ -165,4 +163,4 @@ def open_connection(sid, data):
165163if __name__ == '__main__' :
166164 loop = asyncio .get_event_loop ()
167165 executor = ProcessPoolExecutor ()
168- web .run_app (app , port = 5000 )
166+ web .run_app (app , port = 5079 )
0 commit comments