def test_tee_simple(): "Very simple check with stdout only" chan = StringIO() text = 'Hello' tee = Tee(chan, channel='stdout') print(text, file=chan) nt.assert_equal(chan.getvalue(), text + "\n")
def tchan(self, channel, check='close'): trap = StringIO() chan = StringIO() text = 'Hello' std_ori = getattr(sys, channel) setattr(sys, channel, trap) tee = Tee(chan, channel=channel) print(text, end='', file=chan) setattr(sys, channel, std_ori) trap_val = trap.getvalue() nt.assert_equal(chan.getvalue(), text) if check == 'close': tee.close() else: del tee
def tchan(self, channel): trap = StringIO() chan = StringIO() text = 'Hello' std_ori = getattr(sys, channel) setattr(sys, channel, trap) tee = Tee(chan, channel=channel) print(text, end='', file=chan) trap_val = trap.getvalue() self.assertEqual(chan.getvalue(), text) tee.close() setattr(sys, channel, std_ori) assert getattr(sys, channel) == std_ori
def print_redirect(log_path: Union[Path, str], mode="a"): try: tee = Tee(log_path, mode=mode, channel="stdout") yield tee finally: tee.close()
def __enter__(self): self.orig_stream = getattr(sys, self.channel) self.buffer = MyStringIO() self.tee = Tee(self.buffer, channel=self.channel) setattr(sys, self.channel, self.buffer if self.suppress else self.tee)
def _capture_on(self): self.orig_stdout = sys.stdout self.buffer = StringIO() self.tee = Tee(self.buffer, 'stdout') sys.stdout = self.buffer
df_for_cluster = util.pre_process(df) tree = find_decision_point(df_for_cluster) IM_tree = IM_tree.replace(" ", "") fig_tree.create_tree(tree, config.silhouette) sum_sil = 0.0 max_row = 0 for node in config.process_tree: if node.sil == None: continue parent_log_rows = node.parent.log_rows if node.parent != -1 else node.log_rows sum_sil += (node.sil * (node.log_rows / parent_log_rows)) max_row = node.row if node.row > max_row else max_row total_sil = sum_sil / (max_row + 1) with closing(Tee('log_file.txt', "a", channel="stdout")) as outputstream: print("=============================================") print(time.strftime("%d/%m/%Y %H:%M:%S")) print("{} \nsilhouette threshold: {}".format( config.data_file, config.silhouette_threshold)) print('IM tree: ', IM_tree) print('tree: ', tree) print(config.explain_operator) print('sil: ', config.silhouette) print('total_sil: ', total_sil) fig_tree.create_tree_fig() # activity_set = set(df['activity'].unique())
if path.exists(path1+"/States_SL.txt") == False: print('', file=open(path1+"/States_SL.txt", "w")) if path.exists(path1+"/States_TP.txt") == False: print('', file=open(path1+"/States_TP.txt", "w")) States_Market=path1+dash+"States_Market.txt" States_Order=path1+dash+"States_Order.txt" States_Possible=path1+dash+"States_Possible.txt" States_isOpen=path1+dash+"States_isOpen.txt" States_SL=path1+dash+"States_SL.txt" States_TP=path1+dash+"States_TP.txt" if True:#change from if to while to always loop from IPython.utils.io import Tee from contextlib import closing with closing(Tee("outputfile.txt", "w", channel="stdout")) as outputstream: try: api_key = '4-H0Cb9XAKoBfNmCDO-yFlMf' # your api key api_secret = 'LfpNu5iTL2UGgdknnbM0Do0Ws4edag8ckF70pb3UJNRkYkVM' # your api secret #whenever bitmex_cli is used, 1 api useage instance is tracked by bitmex. Bitmex only allows 15 api calls per minute bitmex_cli = bitmex1(test=False, api_key=api_key, api_secret=api_secret)#this wrapper used due to supporting leverage and the simplicity of creating market/limit orders. Also closes orders. #creating dataframe that will be used to store candlestick data. df=pd.DataFrame() timep= df.append({'time':1}, ignore_index=True) timep=timep.iloc[0:0] openp= df.append({'open':1}, ignore_index=True) openp=openp.iloc[0:0] highp= df.append({'high':2}, ignore_index=True) highp=highp.iloc[0:0] lowp= df.append({'low':3}, ignore_index=True) lowp=lowp.iloc[0:0]
help="Whether to show the GPU utilization on terminal") parser.add_argument("--reverse") args = parser.parse_args() exp_id = args.id tot_exps = args.tot_exps n_trials = args.trials gputil = args.print_gputil gpus = tf.config.experimental.list_physical_devices('GPU') if not os.path.exists('../terminal_logs'): os.makedirs('../terminal_logs') with closing( Tee(f"../terminal_logs/exp{exp_id}.txt", "w", channel="stderr")) as outputstream: # with closing(Tee(f"../terminal_logs/exp{exp_id}_new_epochs.txt", "w", channel="stderr")) as outputstream: if gputil: monitor = Monitor(30) # with StdoutTee(f"../terminal_logs/exp{exp_id}.txt"), StderrTee(f"../terminal_logs/exp{exp_id}_err.txt"): if gpus: try: # Currently, memory growth needs to be the same across GPUs for gpu in gpus: tf.config.experimental.set_memory_growth(gpu, True) logical_gpus = tf.config.experimental.list_logical_devices( 'GPU') print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs") except RuntimeError as e: # Memory growth must be set before GPUs have been initialized