Re: a clean exit
Il 23/07/2021 10:55, jak ha scritto: Hello everybody, I wrote a bot for telegram which consists of some processes of which the main ones are: - the main process: a list of callback functions - a second process: managed with a message queue - a third process: started by the library I use (python-telegram-bot) which is used for the event/error log ('logging' module). The problem is that sometimes I get an error from the library (python- telegram-bot) via logging that my bot has no way of intercepting. The error is "connection reset by pear" after which my program is no longer called and I need to restart it. Typically this happens when Telegram runs an update. In any case I can know this error because, to write a log in a telegram channel, I inherit the 'emit' function of the 'logging.Handler' class. Hoping to have explained clearly enough the context in which the program receives information about the error (we are inside a process not launched directly from the main program), my question is: do you have advice on how I can close my program in the way as clean as possible in a easy way? Thanks in advance. Thanks to both of you for the replies. I know the rules you described to me for process synchronization but unfortunately, due to the structure of the library I am using, I cannot apply them. I can't even use try/except because the library, when the error occurs, displays it with the loggin libraries and no longer calls any of the callback functions my program is composed of. To understand when the error occurs, my only possibility is to intercept the logging, read the error string and, if it is not one of mine (mine all start with ":"), to close the program. Following some examples on the web I also configured a function to handle the error: ''' dispatcher.add_error_handler(callback=fallback_error, run_async=True) ''' but unfortunately after getting that error the library seems to hang and doesn't call my callback function. I was actually hoping to get some tricks to shut down all processes as a suggestion. Could I, for example, create a global list containing the ids of the processes I started and then kill each of them? Can it make sense? ty again -- https://mail.python.org/mailman/listinfo/python-list
Re: Trying to read from a text file to generate a graph
[Resending to the list only, since I couldn't post it without subscribing.] On Wed, 28 Jul 2021 11:58:21 -0400 "Steve" wrote: > I forgot about the no-file rule... > >> On 28Jul2021 02:55, Steve wrote: >> I am going though a struggle with this and just don't see where it >> fails. I am using the Dual Bar Graph.py program from >> https://matplotlib.org/stable/gallery/index.html website. The file >> from the web site works so that shows that all my installations are >> complete. >> >> My program, LibreGraphics 05.py program runs but the graph is all >> smutched up. I am pulling data from the EXCEL-FILE.txt into the >> program, selecting three values for each line and creating three >> variables formatted as is shown in the original demo file. >> >> When you run the program, choose 112 when prompted. You will see the >> values of the variables I want to pass to the graph section of the >> code. If the values are hardcoded, the graphs look good. When the >> variables generated by my section of the code, it does not. The problem is due to the values of Sensors, TestStrips and SampleNumber being strings; what you want is for them to be lists, as in the assignments you commented out. And since the data from the file is read in as strings, you have to cast the elements of the Sensors and TestStrips lists to integers, since you want the numerical values. The following code does the job: Sensors = [] TestStrips = [] SampleNumber = [] x = 1 SensorNumber = input("Enter senaor number: ") with open("_EXCEL-FILE.txt", 'r') as infile: for lineEQN in infile: if (lineEQN[0:1]== "."): SN = lineEQN[44:48].strip() if (SensorNumber == SN): SN = x SampleNumber.append(SN) sv = lineEQN[25:29].strip() Sensors.append(int(sv)) tv = lineEQN[32:37].strip() TestStrips.append(int(tv)) x += 1 labels = SampleNumber Add the rest of your code from the second half to make the desired bar chart. Steve Berman -- https://mail.python.org/mailman/listinfo/python-list
Re: [Errno 2] No such file or directory:
On 28/07/2021 18:09, joseph pareti wrote: The following code fails as shown in the title: *import subprocesscmd = 'ls -l /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48 | awk "{print $9 }"'process = subprocess.Popen([cmd], As a quick fix try process = subprocess.Popen( cmd # no list shell=True, ... # other args as above ) stdout=subprocess.PIPE, stderr=subprocess.PIPE)stdout, stderr = process.communicate()print('stdout ',stdout)print('stderr ',stderr)* Traceback (most recent call last): File "PreProcess_1a.py", line 3, in process = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE) File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 1702, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'ls -l /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48 | awk "{print $9 -- https://mail.python.org/mailman/listinfo/python-list
Re: [Errno 2] No such file or directory:
On Thu, Jul 29, 2021 at 2:10 AM joseph pareti wrote: > > The following code fails as shown in the title: > > > > > > > *import subprocesscmd = 'ls -l > /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48 > | awk "{print $9 }"'process = subprocess.Popen([cmd], > stdout=subprocess.PIPE, stderr=subprocess.PIPE)stdout, stderr = > process.communicate()print('stdout ',stdout)print('stderr ',stderr)* > > > > Traceback (most recent call last): > File "PreProcess_1a.py", line 3, in > process = subprocess.Popen([cmd], stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 854, > in __init__ > self._execute_child(args, executable, preexec_fn, close_fds, > File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line > 1702, in _execute_child > raise child_exception_type(errno_num, err_msg, err_filename) > FileNotFoundError: [Errno 2] No such file or directory: 'ls -l > /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48 > | awk "{print $9 > First off, you'll want to post code in a way that keeps the formatting, otherwise it becomes very hard to read. But the immediate problem here is that Popen takes an array of command arguments, NOT a shell command line. You cannot invoke ls and pipe it into awk this way. Don't think like a shell script. Python has very good directory-listing functionality, and you will very very seldom need to shell out to pipelines. Figure out what you actually need to learn from the directory listing and get that information directly, rather than trying to use two external commands and text parsing. It's far FAR easier, cleaner, and safer that way. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
[Errno 2] No such file or directory:
The following code fails as shown in the title: *import subprocesscmd = 'ls -l /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48 | awk "{print $9 }"'process = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE)stdout, stderr = process.communicate()print('stdout ',stdout)print('stderr ',stderr)* Traceback (most recent call last): File "PreProcess_1a.py", line 3, in process = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE) File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/home/joepareti54/anaconda3/lib/python3.8/subprocess.py", line 1702, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'ls -l /media/joepareti54/Elements/x/finance-2020/AI/Listen_attend_spell/VCTK-Corpus/wav48 | awk "{print $9 -- Regards, Joseph Pareti - Artificial Intelligence consultant Joseph Pareti's AI Consulting Services https://www.joepareti54-ai.com/ cell +49 1520 1600 209 cell +39 339 797 0644 -- https://mail.python.org/mailman/listinfo/python-list
RE: Trying to read from a text file to generate a graph
I forgot about the no-file rule... On 28Jul2021 02:55, Steve wrote: >I am going though a struggle with this and just don't see where it fails. >I am using the Dual Bar Graph.py program from https://matplotlib.org/stable/gallery/index.html website. >The file from the web site works so that shows that all my installations are complete. > >My program, LibreGraphics 05.py program runs but the graph is all smutched up. I am pulling data from the EXCEL-FILE.txt into the program, selecting three values for each line and creating three variables formatted as is shown in the original demo file. > >When you run the program, choose 112 when prompted. You will see the values of the variables I want to pass to the graph section of the code. If the values are hardcoded, the graphs look good. When the variables generated by my section of the code, it does not. > >I am not sure what more to explain. >Please help me >Steve > >I am attaching a zip file. I hope it gets through. Alas, the python-list is text only, and attachments are discarded. Here is my code for the main program: = #https://matplotlib.org/stable/gallery/index.html import matplotlib.pyplot as plt import numpy as np ## In this first half of the program, I am reading lines of data from ## a file and reformatting them to create comms separated values into ## three variables. Sensors = "" TestStrips = "" SampleNumber = "" x = 1 SensorNumber = input("Enter senaor number: ") with open("_EXCEL-FILE.txt" , 'r') as infile: for lineEQN in infile: # loop to find each line in the file for that dose if (lineEQN[0:1]== "."): SN = lineEQN[44:48].strip() if (SensorNumber == SN): SN = x sn = "'" + str(SN) + "', " SampleNumber = SampleNumber + sn sv = lineEQN[25:29].strip() sv = sv + ", " Sensors = Sensors + sv tv = lineEQN[32:37].strip() tv = tv + ", " TestStrips = TestStrips + tv x += 1 SnLen = len(SampleNumber) -2 SampleNumber = SampleNumber[0:SnLen] labels = "[" + SampleNumber + "]" print("labels = " + labels) SenLen = len(Sensors) -2 Sensors = Sensors[0:SenLen] Sensors = "[" + Sensors + "]" print("Sensors = " + Sensors) TsLen = len(TestStrips) -2 TestStrips = TestStrips[0:TsLen] TestStrips = "[" + TestStrips + "]" print("TestStrips = " + TestStrips) labels = SampleNumber ## = ## In this second half of the program, I want to use the three ## variables ## to populate a fraph. ## There are problems with this technique. ## = ## With the following 6 lines of code commented-out, the graphing ## program uses the variables from the first half of the program ## and the graph fails ## = ## Uncommented, the following works by overwriting the variables ## from the previous code and generates a proper graph. #label = ['1', '2', '3', '4', '5'] #Sensor = [150, 132, 182, 75, 117] #TestStrip = [211, 144, 219, 99, 142] #labels = label #Sensors = Sensor #TestStrips = TestStrip ## === ## The follows is the original cose from the sample program ## with minor variable names and label changes. x = np.arange(len(labels)) # the label locations width = 0.35 # the width of the bars fig, ax = plt.subplots() rects1 = ax.bar(x - width/2, Sensors, width, label='Sensors') rects2 = ax.bar(x + width/2, TestStrips, width, label='TestStrips') # Add some text for labels, title and custom x-axis tick labels, etc. ax.set_ylabel('Glucose Readings') ax.set_title('Sensors VS Test Strip') ax.set_xticks(x) ax.set_xticklabels(labels) ax.legend() ax.bar_label(rects1, padding=3) ax.bar_label(rects2, padding=3) fig.tight_layout() plt.show() === And here is a sample of the data file: .Thu Jul 22, 2021 20:47 250 27727 111 2 .Fri Jul 23, 2021 00:05 188 194 6 111 3 .Fri Jul 23, 2021 09:08 142 16624 111 3 .Fri Jul 23, 2021 12:58 138 16527 111 3 .Fri Jul 23, 2021 22:32 356 39135 111 3 .Sat Jul 24, 2021 09:44 150 21161 112 4 .Sat Jul 24, 2021 13:24 132 14412 112 4 .Sat Jul 24, 2021 16:40 182 21331 112 4 .Sat Jul 24, 2021 19:52759924 112 4 .Sat Jul 24, 2021 23:19 117 14225 112 4 -- https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py
On Wednesday, July 28, 2021 at 3:05:11 PM UTC+8, Peter Otten wrote: > On 28/07/2021 07:32, Cameron Simpson wrote: > > On 27Jul2021 19:24, Hongyi Zhao wrote: > >> On Wednesday, July 28, 2021 at 7:25:27 AM UTC+8, cameron...@gmail.com > >> wrote: > >>> Just to follow on a bit to Dennis: > >> > >> But I can't any reply from Dennis in this issue. > > > > Odd, because I replied to his reply to you :-) > Perhaps it has something to do with the X-No-Archive flag set by Dennis? I'm not sure. I use the Google Groups from Firefox for reading from/posting on this group. HY -- https://mail.python.org/mailman/listinfo/python-list
Re: Trying to read from a text file to generate a graph
On 28Jul2021 02:55, Steve wrote: >I am going though a struggle with this and just don't see where it fails. >I am using the Dual Bar Graph.py program from >https://matplotlib.org/stable/gallery/index.html website. >The file from the web site works so that shows that all my installations are >complete. > >My program, LibreGraphics 05.py program runs but the graph is all smutched up. > I am pulling data from the EXCEL-FILE.txt into the program, selecting three >values for each line and creating three variables formatted as is shown in the >original demo file. > >When you run the program, choose 112 when prompted. You will see the values of >the variables I want to pass to the graph section of the code. If the values >are hardcoded, the graphs look good. When the variables generated by my >section of the code, it does not. > >I am not sure what more to explain. >Please help me >Steve > >I am attaching a zip file. I hope it gets through. Alas, the python-list is text only, and attachments are discarded. Is your programme small enough (one file, not insanely long) to just include inline in your next message? Have you printed the variables generated by your code? _Are_ they the same as the hardcoded values? You may want to graph different stuff, but start by trying to exactly reproduce the hardcoded value, but extracted from the file. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Trying to read from a text file to generate a graph
I am going though a struggle with this and just don't see where it fails. I am using the Dual Bar Graph.py program from https://matplotlib.org/stable/gallery/index.html website. The file from the web site works so that shows that all my installations are complete. My program, LibreGraphics 05.py program runs but the graph is all smutched up. I am pulling data from the EXCEL-FILE.txt into the program, selecting three values for each line and creating three variables formatted as is shown in the original demo file. When you run the program, choose 112 when prompted. You will see the values of the variables I want to pass to the graph section of the code. If the values are hardcoded, the graphs look good. When the variables generated by my section of the code, it does not. I am not sure what more to explain. Please help me Steve I am attaching a zip file. I hope it gets through. George Melly remarked to Mike Jagger on how lined his face was for one so young. Jagger replied “They’re laughter lines George” to which Melly countered: “Mick, nothing’s that f**king funny!”. -- https://mail.python.org/mailman/listinfo/python-list
Re: Generate a Google Translate API token through the Socks5 proxy using gtoken.py
On 28/07/2021 07:32, Cameron Simpson wrote: On 27Jul2021 19:24, Hongyi Zhao wrote: On Wednesday, July 28, 2021 at 7:25:27 AM UTC+8, cameron...@gmail.com wrote: Just to follow on a bit to Dennis: But I can't any reply from Dennis in this issue. Odd, because I replied to his reply to you :-) Perhaps it has something to do with the X-No-Archive flag set by Dennis? -- https://mail.python.org/mailman/listinfo/python-list