44import time
55from ast import literal_eval
66import os
7+ import logging
78
89#time.sleep(7)
910timeout_max = 20
5859 except :
5960 init_simtime_ym = "[0.0, 0.0, 0.0]"
6061
61- print ( apikey )
62- print ( yuyu )
63- print ( name1 + '=' + init_simtime_u )
64- print ( name2 + '=' + init_simtime_ym )
62+ logging . info ( f"API Key: { apikey } " )
63+ logging . info ( f"Yuyu: { yuyu } " )
64+ logging . info ( f" { name1 } = { init_simtime_u } " )
65+ logging . info ( f" { name2 } = { init_simtime_ym } " )
6566
6667while not os .path .exists (concore .inpath + '1/' + name1 ):
6768 time .sleep (concore .delay )
7879
7980
8081while (concore .simtime < concore .maxtime ):
81- print ("CW outer loop" )
82+ logging . debug ("CW outer loop" )
8283 while concore .unchanged ():
8384 u = concore .read (1 ,name1 ,init_simtime_u )
8485 f = {'file1' : open (concore .inpath + '1/' + name1 , 'rb' )}
85- print ( "CW: before post u=" + str ( u ) )
86- print ( 'http://www.controlcore.org/pm/' + yuyu + apikey + ' &fetch=' + name2 )
86+ logging . debug ( f "CW: before post u={ u } " )
87+ logging . debug ( f 'http://www.controlcore.org/pm/{ yuyu } { apikey } &fetch={ name2 } ' )
8788 r = requests .post ('http://www.controlcore.org/pm/' + yuyu + apikey + '&fetch=' + name2 , files = f ,timeout = timeout_max )
8889 if r .status_code != 200 :
89- print ( "bad POST request " + str ( r .status_code ) )
90+ logging . error ( f "bad POST request { r .status_code } " )
9091 quit ()
9192 if len (r .text )!= 0 :
9293 try :
9394 t = literal_eval (r .text )[0 ]
9495 except :
95- print ( "bad eval " + r .text )
96+ logging . error ( f "bad eval { r .text } " )
9697 timeout_count = 0
9798 t1 = time .perf_counter ()
98- print ( "CW: after post status=" + str ( r .status_code ) + " r.content=" + str ( r .content ) + " t=" + str ( t ) )
99+ logging . debug ( f "CW: after post status={ r .status_code } r.content={ r .content } t={ t } " )
99100 #while r.text==oldym or len(r.content)==0:
100101 while oldt == t or len (r .content )== 0 :
101102 time .sleep (concore .delay )
102- print ( "CW waiting status=" + str ( r .status_code ) + " content=" + r .content .decode ('utf-8' )+ " t=" + str ( t ) )
103+ logging . debug ( f "CW waiting status={ r .status_code } content={ r .content .decode ('utf-8' )} t={ t } " )
103104 f = {'file1' : open (concore .inpath + '1/' + name1 , 'rb' )}
104105 try :
105106 r = requests .post ('http://www.controlcore.org/pm/' + yuyu + apikey + '&fetch=' + name2 , files = f ,timeout = timeout_max )
106107 except :
107- print ("CW: bad request" )
108+ logging . error ("CW: bad request" )
108109 timeout_count += 1
109110 if r .status_code != 200 or time .perf_counter ()- t1 > 1.1 * timeout_max : #timeout_count>100:
110- print ( "timeout or bad POST request " + str ( r .status_code ) )
111+ logging . error ( f "timeout or bad POST request { r .status_code } " )
111112 quit ()
112113 if len (r .text )!= 0 :
113114 try :
114115 t = literal_eval (r .text )[0 ]
115116 except :
116- print ( "bad eval " + r .text )
117+ logging . error ( f "bad eval { r .text } " )
117118 oldt = t
118119 oldym = r .text
119- print ( "CW: oldym=" + oldym + " t=" + str ( concore .simtime ) )
120+ logging . debug ( f "CW: oldym={ oldym } t={ concore .simtime } " )
120121 concore .write (1 ,name2 ,oldym )
121122#concore.write(1,"ym",init_simtime_ym)
122- print ("retry=" + str (concore .retrycount ))
123-
124-
123+ logging .info (f"retry={ concore .retrycount } " )
0 commit comments