asyncio - how to stop background task cleanly
Hi all It is easy enough to set up a task to run in the background every 10 seconds using asyncio - async def background_task(): while True: await perform_task() await asyncio.sleep(10) asyncio.ensure_future(background_task()) When shutting the main program down, I want to stop the task, but I cannot figure out how to stop it cleanly - i.e. wait until it has finished the current task and possibly performed some cleanup, before continuing. async def background_task(): await perform_setup() while condition: await perform_task() await asyncio.sleep(10) await perform_cleanup() Previously I would run the task in another thread, then set a flag to tell it to stop, then join() the thread which would block until the task had finished. I used threading.Event as the flag, which allows it to 'sleep' using wait() with a timeout value, but reacts instantly when set() is called, so it was ideal. Is there a way to achieve this using asyncio? Thanks Frank Millman -- https://mail.python.org/mailman/listinfo/python-list
Re: Daemon strategy
Ian Kelly writes: > Depends on the version: > https://en.wikipedia.org/wiki/Windows_Services_for_UNIX > https://en.wikipedia.org/wiki/POSIX#POSIX_for_Windows > > Linux and FreeBSD are also not POSIX-certified, even though they > mostly comply. Should pip warn about those also? You're implying that the PyPI trove category “Operating System :: POSIX” includes MS Windows? Or that it excludes Linux and FreeBSD? Or that it's meaningless? -- \ “Drop your trousers here for best results.” —dry cleaner, | `\ Bangkok | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: asyncio - how to stop background task cleanly
"Frank Millman" : > When shutting the main program down, I want to stop the task, but I > cannot figure out how to stop it cleanly - i.e. wait until it has > finished the current task and possibly performed some cleanup, before > continuing. Here (and really, only here) is where asyncio shows its superiority over threads: you can multiplex. You should await asyncio.wait(..., return_when=asyncio.FIRST_COMPLETED) to deal with multiple alternative stimuli. In fact, since there is always a minimum of two alternative stimuli to await, you should only ever await asyncio.wait(). And, while viable, that's what makes every asyncio program ugly as hell. Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Exception handling for socket.error in Python 3.5/RStudio
Hi Martin, Thanks for the detailed reply. I edited, saved and opened the file again. Still I am getting exactly the same error. Putting bigger chunk of code and the error again: # create socket s = socket.socket(socket.AF_INET) #create a SSL context with the recommended security settings for client sockets, including automatic certificate verification: context = ssl.create_default_context() # Alternatively, a customized context could be created: #context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) #context.verify_mode = ssl.CERT_REQUIRED #context.check_hostname = True # Load a set of default CA certificates from default locations #context.load_default_certs() ssl_sock = context.wrap_socket(s, server_hostname ='firehose.flightaware.com ') print("Connecting...") ssl_sock.connect(('firehose.flightaware.com', 1501)) print("Connection succeeded") # send initialization command to server: ssl_sock.write(bytes(initiation_command, 'UTF-8')) # return a file object associated with the socket file = ssl_sock.makefile('r') # use "while True" for no limit in messages received count = 10 while (count > 0): try : # read line from file: print(file.readline()) # parse parse_json(file.readline()) count = count - 1 except socket.error as e: print('Connection fail', e) print(traceback.format_exc()) # wait for user input to end # input("\n Press Enter to exit..."); # close the SSLSocket, will also close the underlying socket ssl_sock.close() -- Error: except socket.error as e: ^ SyntaxError: invalid syntax TIA. On Fri, Feb 5, 2016 at 1:44 PM, Martin A. Brown wrote: > > Hi there Shaunak, > > I saw your few replies to my (and Nathan's) quick identification of > syntax error. More comments follow, here. > > >I am running this python script on R-studio. I have Python 3.5 installed > on my system. > > > >count = 10 > >while (count > 0): > >try : > ># read line from file: > >print(file.readline()) > ># parse > >parse_json(file.readline()) > >count = count - 1 > >except socket.error as e > >print('Connection fail', e) > >print(traceback.format_exc()) > > > ># wait for user input to end > ># input("\n Press Enter to exit..."); > ># close the SSLSocket, will also close the underlying socket > >ssl_sock.close() > > > >The error I am getting is here: > > > >line 53 except socket.error as e ^ SyntaxError: invalid syntax > > > >I tried changing socket.error to ConnectionRefusedError. and still got > the same error. > > We were assuming that line 53 in your file is the part you pasted > above. That clearly shows a syntax error (the missing colon). > > If, after fixing that error, you are still seeing errors, then the > probable explanations are: > > * you are not executing the same file you are editing > > * there is a separate syntax error elsewhere in the file (you sent > us only a fragment) > > Additional points: > > * While the word 'file' is not reserved in Python 3.x, it is in > Python 2.x, so, just be careful when working with older Python > versions. You could always change your variable name, but you > do not need to. > > * When you catch the error in the above, you print the traceback > information, but your loop will continue. Is that what you > desired? > > I might suggest saving your work carefully and make sure that you > are running the same code that you are working on. Then, if you > are still experiencing syntax errors, study the lines that the > interpreter is complaining about. And, of course, send the list an > email. > > Best of luck, > > -Martin > > -- > Martin A. Brown > http://linux-ip.net/ > -- https://mail.python.org/mailman/listinfo/python-list
Re: Exception handling for socket.error in Python 3.5/RStudio
Hi Martin, Answering your questions below: On Fri, Feb 5, 2016 at 1:50 PM, Shaunak Bangale wrote: > Hi Martin, > > Thanks for the detailed reply. I edited, saved and opened the file again. > Still I am getting exactly the same error. > > Putting bigger chunk of code and the error again: > > > > # create socket > s = socket.socket(socket.AF_INET) > #create a SSL context with the recommended security settings for client > sockets, including automatic certificate verification: > context = ssl.create_default_context() > # Alternatively, a customized context could be created: > #context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) > #context.verify_mode = ssl.CERT_REQUIRED > #context.check_hostname = True > # Load a set of default CA certificates from default locations > #context.load_default_certs() > > ssl_sock = context.wrap_socket(s, server_hostname =' > firehose.flightaware.com') > print("Connecting...") > ssl_sock.connect(('firehose.flightaware.com', 1501)) > print("Connection succeeded") > > # send initialization command to server: > ssl_sock.write(bytes(initiation_command, 'UTF-8')) > # return a file object associated with the socket > file = ssl_sock.makefile('r') > # use "while True" for no limit in messages received > count = 10 > while (count > 0): > try : > # read line from file: > print(file.readline()) > # parse > parse_json(file.readline()) > count = count - 1 > except socket.error as e: > print('Connection fail', e) > print(traceback.format_exc()) > > > # wait for user input to end > # input("\n Press Enter to exit..."); > # close the SSLSocket, will also close the underlying socket > ssl_sock.close() > > -- > > Error: > except socket.error as e: > ^ > SyntaxError: invalid syntax > > > TIA. > > > > > > On Fri, Feb 5, 2016 at 1:44 PM, Martin A. Brown > wrote: > >> >> Hi there Shaunak, >> >> I saw your few replies to my (and Nathan's) quick identification of >> syntax error. More comments follow, here. >> >> >I am running this python script on R-studio. I have Python 3.5 installed >> on my system. >> > >> >count = 10 >> >while (count > 0): >> >try : >> ># read line from file: >> >print(file.readline()) >> ># parse >> >parse_json(file.readline()) >> >count = count - 1 >> >except socket.error as e >> >print('Connection fail', e) >> >print(traceback.format_exc()) >> > >> ># wait for user input to end >> ># input("\n Press Enter to exit..."); >> ># close the SSLSocket, will also close the underlying socket >> >ssl_sock.close() >> > >> >The error I am getting is here: >> > >> >line 53 except socket.error as e ^ SyntaxError: invalid syntax >> > >> >I tried changing socket.error to ConnectionRefusedError. and still got >> the same error. >> >> We were assuming that line 53 in your file is the part you pasted >> above. That clearly shows a syntax error (the missing colon). >> >> If, after fixing that error, you are still seeing errors, then the >> probable explanations are: >> >> * you are not executing the same file you are editing >> >> * there is a separate syntax error elsewhere in the file (you sent >> us only a fragment) >> >> Additional points: >> >> * While the word 'file' is not reserved in Python 3.x, it is in >> Python 2.x, so, just be careful when working with older Python >> versions. You could always change your variable name, but you >> do not need to. >> >> But according to FlighAware, this code is supposed to work on the Python 3.X and I have Python 3.5 on my computer and I am hoping the same is being used by Rstudio. > * When you catch the error in the above, you print the traceback >> information, but your loop will continue. Is that what you >> desired? >> >> Yes, I want the loop to run 10 times. > I might suggest saving your work carefully and make sure that you >> are running the same code that you are working on. Then, if you >> are still experiencing syntax errors, study the lines that the >> interpreter is complaining about. And, of course, send the list an >> email. >> >> The same code is supposedly running on a mac machine- Rstudio. I am not sure if the issue is also with Windows 7- Rstudio- Python 3.5 combo. > Best of luck, >> >> -Martin >> >> -- >> Martin A. Brown >> http://linux-ip.net/ >> > > -- https://mail.python.org/mailman/listinfo/python-list
Re: Exception handling for socket.error in Python 3.5/RStudio
I do have the initiation command defined. Just that I am not allowed to make the username, pwd public. I am absolutely sure I am running the same code. Now opened the same file with Python 3.5 shell and I get following error: from _ssl import RAND_status, RAND_egd, RAND_add ImportError: cannot import name 'RAND_egd' I am new to coding and this code has been borrowed from an online source but I can see same code working on mac+Rstudio+python combo. Salute your patience. Sincerely, On Fri, Feb 5, 2016 at 2:01 PM, Martin A. Brown wrote: > > Hi there, > > >Thanks for the detailed reply. I edited, saved and opened the file > >again. Still I am getting exactly the same error. > > > >Putting bigger chunk of code and the error again: > > [snipped; thanks for the larger chunk] > > >Error: > >except socket.error as e: > > ^ > >SyntaxError: invalid syntax > > I ran your code. I see this: > > $ python3 shaunak.bangale.py > Connecting... > Connection succeeded > Traceback (most recent call last): > File "shaunak.bangale.py", line 23, in > ssl_sock.write(bytes(initiation_command, 'UTF-8')) > NameError: name 'initiation_command' is not defined > > Strictly speaking, I don't think you are having a Python problem. > > * Are you absolutely certain you are (or your IDE is) executing > the same code you are writing? > > * How would you be able to tell? Close your IDE. Run the code on > the command-line. > > * How much time have you taken to work out what the interpreter is > telling you? > > Good luck, > > -Martin > > -- > Martin A. Brown > http://linux-ip.net/ > > -- https://mail.python.org/mailman/listinfo/python-list
Re: Daemon strategy
As Ben already said .. either deploy to Unix systems or use subprocess.Popen and detach the process: from subprocess import Popenfrom win32process import DETACHED_PROCESS Popen(["YOURPROCESS"],creationflags=DETACHED_PROCESS,shell=True) On Fri, Feb 5, 2016 at 10:52 AM, Ben Finney wrote: > paul.hermeneu...@gmail.com writes: > > > It appears that python-deamon would be exactly what I need. Alas, > > appears not to run on Windows. If I am wrong about that, please tell > > me. > > You're correct that ‘python-daemon’ uses Unix facilities to create a > well-behaved Unix daemon process. > > Since MS Windows lacks those facilities, ‘python-daemon’ can't use them. > > > To what tools should I turn? > > If what you need – the support to create a Unix daemon process – is > available only on Unix by definition, it seems you'll need to deploy to > Unix. > > > I am not eager to produce a "service" on Windows unless it cannot be > > avoided. > > Agreed :-) > > -- > \ “Wrinkles should merely indicate where smiles have been.” —Mark | > `\Twain, _Following the Equator_ | > _o__) | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > -- *Timo Furrer* https://github.com/timofurrer tuxt...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: realtime output and csv files
On 2016-02-06 02:53, Bernardo Sulzbach wrote: >> And even if you have things to escape or format correctly, the >> stdlib has a "csv" module that makes this trivially easy: >> > > I supposed it had one. Obviously, I've never used it myself, > otherwise I would be sure about its existence. Nice to know about > it, although I assume that for many data transfers it will not be > painless if you need several escapes, when CSV starts to become > complicated it starts to fail because of quirky and naive parsers. If you read up on the csv module's help, it has all manner of knobs to twiddle when it comes to the "dialect" of CSV: - delimiters: comma is the default, but you can specify others like tab or pipe) - quote character: double-quote is the default, but you can use single-quote or otherwise - escaping: doubling up the quote-character is the default but I think you can specify other schemes There are others, but that's what I have to tweak most often. Finally, there's a sniffer in the module, so even if you don't know the format, you can make an intelligent guess about it: with open('example.csv', 'rb') as csvfile: dialect = csv.Sniffer().sniff(csvfile.read(1024*4)) csvfile.seek(0) reader = csv.reader(csvfile, dialect) The only edge case I've hit regularly is that it doesn't (didn't? not sure if it's been fixed) do the right thing on CSV files containing a single column, as it would try to accept a common alphanumeric character as the delimiter instead of making the better assumption that it was a single column. -tkc -- https://mail.python.org/mailman/listinfo/python-list
Re: realtime output and csv files
I wouldn't be surprised if a parser treated a value as text only because it has spaces on it. For OP, if you are going for this, I - personally - suggest sticking to "%d,%2d:%2d,%.1f". you're rightin fact importing datas in spreadsheet I've had some problems. I'll follow this suggestion. tnks a lot! :) -- https://mail.python.org/mailman/listinfo/python-list
Re: asyncio - how to stop background task cleanly
"Marko Rauhamaa" wrote in message news:87lh6ys052@elektro.pacujo.net... "Frank Millman" : > When shutting the main program down, I want to stop the task, but I > cannot figure out how to stop it cleanly - i.e. wait until it has > finished the current task and possibly performed some cleanup, before > continuing. Here (and really, only here) is where asyncio shows its superiority over threads: you can multiplex. You should await asyncio.wait(..., return_when=asyncio.FIRST_COMPLETED) to deal with multiple alternative stimuli. Thanks, Marko, that works very well. It took me a while to get it working, because I initiate shutting down the program from another thread. Eventually I figured out that I could put all my event loop shutdown procedures into a coroutine, and then call asyncio.run_coroutine_threadsafe() from the main thread. Now I just have one problem left. I will keep experimenting, but if someone gives me a hint in the meantime it will be appreciated. I run my background task like this - stop_task = False async def background_task(): while not stop_task: await perform_task() await asyncio.sleep(10) I stop the task by setting stop_task to True. It works, but it waits for the 10-second sleep to expire before it is actioned. With threading, I could set up a threading.Event(), call evt.wait(timeout=10) to run the loop, and evt.set() to stop it. It stopped instantly. Is there an equivalent in asyncio? Thanks Frank -- https://mail.python.org/mailman/listinfo/python-list
python
I would like to know how to open your python launcher to start coding on windows 8 the python version I have installed is python 3.5.1 but it keeps giving me an instillation set up Sent from Windows Mail -- https://mail.python.org/mailman/listinfo/python-list
Re: python
On 06/02/2016 13:40, jill davies wrote: I would like to know how to open your python launcher to start coding on windows 8 the python version I have installed is python 3.5.1 but it keeps giving me an instillation set up hello and welcome. Your question has been asked and answered repeatedly over the last few months so please search the archives for the solution. You might also like to consider giving a rather more specific subject for your next question. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: _siftup and _siftdown implementation
As the comments in the heapq module says, in most of the cases (probability 0.837 [from knuth vol3]) the the new inserted element whose initial location is end of the array, which means that it will be larger than the `pos` children. So the old version and new version code is same in these cases because in old version the comparison is taking place at line 129, in the new version comparison is taking place inside _siftdown. SO the total number of comparisons are not decreased by those cases the other type case is the swapped element is smaller than `pos` parents, in this case the old version does a comparison and then goto _sifdown but in the new version _siftdown will be executed and then it comes to _siftup, here in 50% of the cases(len(heap last level) == len(heap) // 2) the pos doesn't have a child, so no comparison. `pos` | probability | `old version comparisons` | `new version comparisions` last level| 0.5| 1 | 0 last - 1 level| 0.25 | 1 | 1 lower levels | 0.25 | 1 | >=1 as the new version doesn't do a comparison if it is in the last level, the optimization is occurring in that place. Which makes the reason behind the heapq module's choice of _siftup code is not at all related to this cause. PS: please copy the table to some text editor, for better visualization. On Fri, Feb 5, 2016 at 11:12 PM, srinivas devaki wrote: > wow, that's great. > you read a comment in the code, and you test it, to only find that it > is indeed true, > sounds ok, but feels great. :) > > Just experimenting a bit, I swaped the lines _siftdown and _siftup and > something > strange happened the number of comparisions in both the versions remained > same. > I'm attaching the files. > > do you have any idea why this happened? > > On Fri, Feb 5, 2016 at 9:57 PM, Sven R. Kunze wrote: >> >> Can we do better here? >> > I don't know, I have to read TAOP knuth article. > > -- > Regards > Srinivas Devaki > Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad) > Computer Science and Engineering Department > ph: +91 9491 383 249 > telegram_id: @eightnoteight -- Regards Srinivas Devaki Junior (3rd yr) student at Indian School of Mines,(IIT Dhanbad) Computer Science and Engineering Department ph: +91 9491 383 249 telegram_id: @eightnoteight -- https://mail.python.org/mailman/listinfo/python-list
Re: python
On Sat, Feb 6, 2016 at 8:40 AM, jill davies wrote: > > > > > I would like to know how to open your python launcher to start coding on > windows 8 the python version I have installed is python 3.5.1 but it keeps > giving me an instillation set up > > > Sent from Windows Mail > -- > https://mail.python.org/mailman/listinfo/python-list Open up the command window type python You are now in the interactive python shell If you want to run a program you have saved in a file type: python my_file.py -- Joel Goldstick http://joelgoldstick.com/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Re: asyncio - how to stop background task cleanly
"Frank Millman" : > "Marko Rauhamaa" wrote in message news:87lh6ys052@elektro.pacujo.net... >> You should >> >>await asyncio.wait(..., return_when=asyncio.FIRST_COMPLETED) >> >> to deal with multiple alternative stimuli. >> > > Thanks, Marko, that works very well. > > [...] > > Now I just have one problem left. I will keep experimenting, but if > someone gives me a hint in the meantime it will be appreciated. > > I run my background task like this - > >stop_task = False > >async def background_task(): >while not stop_task: >await perform_task() >await asyncio.sleep(10) You should set up a separate asyncio.Event or asyncio.Queue to send "out-of-band" signals to your background_task: async def background_task(cancel_event): async def doze_off(): await asyncio.sleep(10) while True: await asyncio.wait( perform_task, cancel_event.wait, return_when=asyncio.FIRST_COMPETED) if cancel_event_is_set() break await asyncio.wait( doze_off, cancel_event.wait, return_when=asyncio.FIRST_COMPETED) if cancel_event_is_set() break That should be the idea, anyway. I didn't try it out. > I stop the task by setting stop_task to True. It works, but it waits for > the 10-second sleep to expire before it is actioned. > > With threading, I could set up a threading.Event(), call > evt.wait(timeout=10) to run the loop, and evt.set() to stop it. It > stopped instantly. > > Is there an equivalent in asyncio? Yes, you could simplify the above thusly: async def background_task(cancel_event): while True: await asyncio.wait( perform_task, cancel_event.wait, return_when=asyncio.FIRST_COMPETED) if cancel_event_is_set() break await asyncio.wait( cancel_event.wait, timeout=10, return_when=asyncio.FIRST_COMPETED) if cancel_event_is_set() break Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Daemon strategy
On Fri, Feb 5, 2016 at 4:10 PM, Ben Finney wrote: > paul.hermeneu...@gmail.com writes: > >> On Fri, Feb 5, 2016 at 11:52 AM, Ben Finney >> wrote: >> > Since MS Windows lacks those facilities, ‘python-daemon’ can't use >> > them. >> >> As you might imagine, I am not always able to specify which OS is >> deployed. That does not mean that I am not responsible for getting the >> work done. Perhaps you will tell me that what I want is not a daemon. > > I'm telling you none of those. What I'm telling you is MS Windows does > not support what is needed to make a Unix daemon. > > You may need to re-visit the requirements and negotiate something > different — a different deployment platform, or something which MS > Windows can do which is less than a proper Unix daemon. I fully understand that Windows is not a proper UNIX. It might be that UNIX is not in each and every aspect a proper Windows. If it is possible, I would like to create one tool to do this rather than multiple. Is there anything in Python that would help to accomplish this goal? -- https://mail.python.org/mailman/listinfo/python-list
Re: Daemon strategy
> As Ben already said .. either deploy to Unix systems or use > subprocess.Popen and detach the process: > > from subprocess import Popenfrom win32process import DETACHED_PROCESS > Popen(["YOURPROCESS"],creationflags=DETACHED_PROCESS,shell=True) This sounds promising. What are the common methods to communicate with the subprocess? I need to query the status and change some settings for the running process? -- https://mail.python.org/mailman/listinfo/python-list
Re: Daemon strategy
On Sat, Feb 6, 2016 at 1:15 AM, Ben Finney wrote: > Ian Kelly writes: > >> Depends on the version: >> https://en.wikipedia.org/wiki/Windows_Services_for_UNIX >> https://en.wikipedia.org/wiki/POSIX#POSIX_for_Windows >> >> Linux and FreeBSD are also not POSIX-certified, even though they >> mostly comply. Should pip warn about those also? > > You're implying that the PyPI trove category “Operating System :: POSIX” > includes MS Windows? Or that it excludes Linux and FreeBSD? Or that it's > meaningless? Mostly the latter. At least it's not very clear as to what OSes are sufficiently compliant to be considered supported. Anything that claims POSIX support might work in Cygwin, or it might not. Who knows? -- https://mail.python.org/mailman/listinfo/python-list
Issues with to run python
Dear Technician, I am writing to you because I have downloaded Python,I have followed all the instructions, but for some reason I am unable to use it. I am sending to you a screen shot, so in that way you can have an idea of what is going on. I have already repaired and modified, but all the time I am back to the same screen, that shows the same different options that can appreciate on the screen shot that I am sending to you. Those options are : Modify Repair Uninstall I will like to have some feedback and further instructions if they are need it. Thanks for your time. Danisa Andrea Alejo Northeastern University Cellphone number: 617-431-0280 -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues with to run python
Sent from my iPhone On Feb 6, 2016, at 3:10 PM, Dánisa Andrea Alejo García mailto:alejo...@hotmail.com>> wrote: Dear Technician, I am writing to you because I have downloaded Python,I have followed all the instructions, but for some reason I am unable to use it. I am sending to you a screen shot, so in that way you can have an idea of what is going on. I have already repaired and modified, but all the time I am back to the same screen, that shows the same different options that you can appreciate on the screen shot that I am sending to you as an attachment . Those options are : Modify Repair Uninstall I will like to have some feedback and further instructions if they are need it. Thanks for your time. Danisa Andrea Alejo Northeastern University Cellphone number: 617-431-0280 -- https://mail.python.org/mailman/listinfo/python-list
Re: asyncio - how to stop background task cleanly
Marko Rauhamaa : > async def background_task(cancel_event): > while True: > await asyncio.wait( > perform_task, cancel_event.wait, > return_when=asyncio.FIRST_COMPETED) > if cancel_event_is_set() > break > await asyncio.wait( > cancel_event.wait, timeout=10, > return_when=asyncio.FIRST_COMPETED) > if cancel_event_is_set() > break [Typo: cancel_event_is_set() ==> cancel_event.is_set().] Actually, cancellation is specially supported in asyncio (https://docs.python.org/3/library/asyncio-task.html#asyncio.Task.cancel>) so this should do: async def background_task(): while True: await perform_task() await asyncio.sleep(10) Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
On Wednesday, February 3, 2016 at 12:02:35 AM UTC-6, John Ladasky wrote: > Rick, you don't like Python? If i didn't like Python, then i would happily let it self- destruct, yes? The problem is, i *DO* like Python. Python2 was a great language, but python3 has been a disaster. Heck, even the BDFL has warned that Python4 cannot introduce as many backwards incompatible changes as python3. So obviously, he is admitting that Python3 was a disaster. -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues with to run python
On Sat, Feb 6, 2016 at 2:10 PM, Dánisa Andrea Alejo García wrote: > I am writing to you because I have downloaded Python,I have followed all the > instructions, but for some reason I am unable to use it. This is a very common question of late. If you search the list archives, you will probably find your answer. I'll just add that if you are using Win XP, you can only use <= Python 3.4.x. Win XP won't work with >= Python 3.5.x. But if by searching the archives you cannot answer your question, then you will need to provide additional information: What is your OS? Which Python version are you trying to install? What exact steps did you take? How did you attempt to start Python? Etc. > I am sending to you a screen shot, so in that way you can have an idea of > what is going on. I have already repaired and modified, but all the time I > am back to the same screen, that shows the same different options that can > appreciate on the screen shot that I am sending to you. Those options are : > > Modify > > Repair > > Uninstall This is a plain text only list, so your screen shot attachment is useless here. boB -- https://mail.python.org/mailman/listinfo/python-list
Re: Daemon strategy
Ian Kelly writes: > On Sat, Feb 6, 2016 at 1:15 AM, Ben Finney wrote: > > You're implying that the PyPI trove category “Operating System :: POSIX” > > includes MS Windows? Or that it excludes Linux and FreeBSD? Or that it's > > meaningless? > > At least it's not very clear as to what OSes are sufficiently > compliant to be considered supported. Anything that claims POSIX > support might work in Cygwin, or it might not. Who knows? That the category is not perfectly reliable doesn't argue for ignoring it altogether. I'm saying that the information is available to ‘pip’ for it to help the use determine whether the package will be useful to them. And that the user, in this instance, has a good case to report a bug against ‘pip’ requesting that it should do that. -- \ “Faith may be defined briefly as an illogical belief in the | `\ occurrence of the improbable.” —Henry L. Mencken | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Simple tkinter query about creating a tk,StringVar() failure
I know this may be more suited to the tutor list. I tried to subscribe, but no response yet. Why does this interactive instantiation fail when it seems to work when run in a script? (py35-64) C:\src\pygui>python Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter as tk >>> name = tk.StringVar() Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Python35\lib\tkinter\__init__.py", line 329, in __init__ Variable.__init__(self, master, value, name) File "C:\Program Files\Python35\lib\tkinter\__init__.py", line 233, in __init__ self._root = master._root() AttributeError: 'NoneType' object has no attribute '_root' -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple tkinter query about creating a tk,StringVar() failure
On 2016-02-07 00:38:14, paul.hermeneu...@gmail.com wrote: I know this may be more suited to the tutor list. I tried to subscribe, but no response yet. Why does this interactive instantiation fail when it seems to work when run in a script? (py35-64) C:\src\pygui>python Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. import tkinter as tk name = tk.StringVar() Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Python35\lib\tkinter\__init__.py", line 329, in __init__ Variable.__init__(self, master, value, name) File "C:\Program Files\Python35\lib\tkinter\__init__.py", line 233, in __init__ self._root = master._root() AttributeError: 'NoneType' object has no attribute '_root' It's just down to the way that tkinter works. It's normally called within a GUI program which has windows and an event loop, and it's trying to get the root (top-level) window, but there isn't one. -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple tkinter query about creating a tk,StringVar() failure
On Sat, Feb 6, 2016 at 6:38 PM, wrote: > Why does this interactive instantiation fail when it seems to work > when run in a script? You have to establish your root window first: Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter as tk >>> root = tk.Tk()# This will open an empty window. >>> name = tk.StringVar() >>> -- boB -- https://mail.python.org/mailman/listinfo/python-list
Python's import situation has driven me to the brink of imsanity
No, that's not a typo, it's the name of a package I created. :) The problems I have with python's import system are detailed in the README of my package here: https://github.com/vadimg/imsanity Basically, relative imports are broken if you like running scripts as executables, so the only real solution is modifying PYTHONPATH every time you switch projects, which is also not ideal. Some people suggest adding various boilerplate to the beginning of every file to fix this, ranging from the crazy stuff in PEP 0366 to the slightly more sane sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__), path_to_root))), where path_to_root is some number of '../'s depending on the file's location. Neither can be used indiscriminately as a macro, which is annoying. Imsanity allows you to make imports usable (not ideal, but at least usable) for python projects without having to manage PYTHONPATHs or do whacky stuff like running files with python -m or put even whackier boilerplate at the top of every file. And all it requires is 'import imsanity' at the top of every file. You can put it in a macro or even just type it because it's short and easy to remember. My question is: is this crazy? Please tell me there's a better way and I just wasted my time creating this package. There's nothing I'd like to hear more. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python's import situation has driven me to the brink of imsanity
On Sun, Feb 7, 2016 at 1:47 PM, wrote: > Imsanity allows you to make imports usable (not ideal, but at least usable) > for python projects without having to manage PYTHONPATHs or do whacky stuff > like running files with python -m or put even whackier boilerplate at the top > of every file. And all it requires is 'import imsanity' at the top of every > file. You can put it in a macro or even just type it because it's short and > easy to remember. > > My question is: is this crazy? Please tell me there's a better way and I just > wasted my time creating this package. There's nothing I'd like to hear more. Well, anything that makes you type "import imsanity" at the top of every script MUST be crazy. :) I don't know about the actual content/purpose though. Good luck with it! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
Python 3 is a disaster because of incompatibility with Python 2. Python 3 itself is not so bad. We can help disaster recovery by stop using Python 2 as possible. Let's stop using legacy Python! On Sun, Feb 7, 2016 at 5:54 AM, Rick Johnson wrote: > On Wednesday, February 3, 2016 at 12:02:35 AM UTC-6, John Ladasky wrote: > > > Rick, you don't like Python? > > If i didn't like Python, then i would happily let it self- > destruct, yes? The problem is, i *DO* like Python. Python2 > was a great language, but python3 has been a disaster. Heck, > even the BDFL has warned that Python4 cannot introduce as > many backwards incompatible changes as python3. So obviously, > he is admitting that Python3 was a disaster. > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- INADA Naoki -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
On Sun, Feb 7, 2016 at 2:02 PM, INADA Naoki wrote: > Python 3 is a disaster because of incompatibility with Python 2. Python 3 > itself is not so bad. > We can help disaster recovery by stop using Python 2 as possible. > > Let's stop using legacy Python! > It's not even a disaster. It's fairly easy to write 2/3 compatible code; in fact, a lot of my students end up accidentally running their code under Py2 and only notice when they get strange errors from input() with non-integers, or maybe if they use print() and get an empty tuple displayed, or something like that. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Daemon strategy
On 02/06/2016 09:04 AM, paul.hermeneu...@gmail.com wrote: > On Fri, Feb 5, 2016 at 4:10 PM, Ben Finney wrote: >> paul.hermeneu...@gmail.com writes: >> >>> On Fri, Feb 5, 2016 at 11:52 AM, Ben Finney >>> wrote: Since MS Windows lacks those facilities, ‘python-daemon’ can't use them. >>> >>> As you might imagine, I am not always able to specify which OS is >>> deployed. That does not mean that I am not responsible for getting the >>> work done. Perhaps you will tell me that what I want is not a daemon. >> >> I'm telling you none of those. What I'm telling you is MS Windows does >> not support what is needed to make a Unix daemon. >> >> You may need to re-visit the requirements and negotiate something >> different — a different deployment platform, or something which MS >> Windows can do which is less than a proper Unix daemon. > > I fully understand that Windows is not a proper UNIX. It might be that > UNIX is not in each and every aspect a proper Windows. > > If it is possible, I would like to create one tool to do this rather > than multiple. Is there anything in Python that would help to > accomplish this goal? The fairly standard python-win32 package certainly allows you to make a proper win32 service. It's not part of the standard library, but you could ship it with your package. http://ryrobes.com/python/running-python-scripts-as-a-windows-service/ It's just not practical to have one tool that does such an OS-dependent thing. But it's not that hard to have specific code for Windows. -- https://mail.python.org/mailman/listinfo/python-list
Re: asyncio - how to stop background task cleanly
"Marko Rauhamaa" wrote in message news:8737t5shhp@elektro.pacujo.net... > Actually, cancellation is specially supported in asyncio (https://docs.python.org/3/library/asyncio-task.html#asyncio.Task.cancel>) so this should do: async def background_task(): while True: await perform_task() await asyncio.sleep(10) That's exactly what I needed - thanks, Marko async def background_task() try: while True: await perform_task() await asyncio.sleep(10) except asyncio.CancelledError: await perform_cleanup() At startup - task = asyncio.ensure_future(background_task()) At shutdown - task.cancel() await asyncio.wait([task]) Works perfectly - thanks again. Frank -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
On Sunday 07 February 2016 14:02, INADA Naoki wrote: > Python 3 is a disaster because of incompatibility with Python 2. How is that a disaster? What is your criteria for deciding what is, and isn't, a disaster? According to TIOBE, Python's popularity continues to grow: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html and is in the top five, above PHP and Javascript. Likewise with IEEE Spectrum, that puts Python in the top 5 most popular languages for 2015, above C#, PHP and Javascript. http://spectrum.ieee.org/computing/software/the-2015-top-ten-programming- languages According to CodeEval, Python has *dominated* at #1 for the fourth year in a row: http://blog.codeeval.com/codeevalblog/2015 It continues to capture more of the scientific computing niche: http://www.johndcook.com/blog/2015/07/16/scientific-computing-in-python/ and Python's broader ecosystem continues to grow, with at least six powerful add-ons for speeding up Python: - cython - numba - theano - copperhead - parakeet - blaze and more. The future looks brighter than ever for Python. How it is a disaster? -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: Python's import situation has driven me to the brink of imsanity
> My question is: is this crazy? Please tell me there's a better way and I just wasted my time creating this package. There is a better way and you have wasted your time creating this package. I hear your problem statement as asking two questions. The first is: What is the right way to include executable content in my Python project? The second is: How do I expose executable content from a Python project? As to the first question, from your project README: > Say you have a python project (not a package), with the following structure: All Python code that you want to install and make available in any form, import or executable, _must_ be contained within a Python package. Organizing Python code in any way other than Python packages will result in the challenges you have described. The correct way to include executable content is to place the Python code within the package structure. It should not be put in other directories within the repository root. As to the second question, once all Python code is contained within a package that can be installed you can use setuptools entry points to expose the executable code. The setup() function from setuptools that is used to create setup.py files has an argument called 'entry_points' that allows you to expose executable content over the command line. See [1] and [2] for more details. Feel free to reach out to me off-list if you have a specific project you need advice on. The rules for organizing and packaging Python code aren't complex but they tend to cause new Python developers to stumble at first. A general rule I give everyone when talking about packaging or importing code: If you have to modify sys.path to makes something work then you have most certainly made a mistake. [1] https://pythonhosted.org/setuptools/setuptools.html#automatic-script-creation [2] http://python-packaging.readthedocs.org/en/latest/command-line-scripts.html#the-console-scripts-entry-point On Sat, Feb 6, 2016 at 8:54 PM Chris Angelico wrote: > On Sun, Feb 7, 2016 at 1:47 PM, wrote: > > Imsanity allows you to make imports usable (not ideal, but at least > usable) for python projects without having to manage PYTHONPATHs or do > whacky stuff like running files with python -m or put even whackier > boilerplate at the top of every file. And all it requires is 'import > imsanity' at the top of every file. You can put it in a macro or even just > type it because it's short and easy to remember. > > > > My question is: is this crazy? Please tell me there's a better way and I > just wasted my time creating this package. There's nothing I'd like to hear > more. > > Well, anything that makes you type "import imsanity" at the top of > every script MUST be crazy. :) I don't know about the actual > content/purpose though. Good luck with it! > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
Steven D'Aprano writes: > According to TIOBE, Python's popularity continues to grow: > http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html I wonder how much of that growth is Python 3 and how much is Python 2. I'm amazed there's still so much C being done. I meet good programmers all the time these days, who have never touched C code. The crash of Objective-C is amusing ;-). It's surprising that R places at all, given the amount of math that its users need to know. I wonder what it means that Perl is booming. Hmm. -- https://mail.python.org/mailman/listinfo/python-list
Re: asyncio - how to stop background task cleanly
"Frank Millman" wrote in message news:n96kjr$mvl$1...@ger.gmane.org... "Marko Rauhamaa" wrote in message news:8737t5shhp@elektro.pacujo.net... > Actually, cancellation is specially supported in asyncio ( https://docs.python.org/3/library/asyncio-task.html#asyncio.Task.cancel>) > so this should do: > > async def background_task(): > while True: > await perform_task() > await asyncio.sleep(10) > That's exactly what I needed - thanks, Marko async def background_task() try: while True: await perform_task() await asyncio.sleep(10) except asyncio.CancelledError: await perform_cleanup() At startup - task = asyncio.ensure_future(background_task()) At shutdown - task.cancel() await asyncio.wait([task]) Works perfectly - thanks again. Alas, I spoke too soon. I tried to simulate what would happen if the background task was busy with a task when it was cancelled - async def background_task() try: while True: print('start') time.sleep(2) print('done') await asyncio.sleep(10) except asyncio.CancelledError: print('cleanup') print('DONE') If I cancel after a pair of 'start/done' appear, the background task is in the 'asyncio.sleep' stage. The words 'cleanup' and 'DONE' appear instantly, and the program halts. If I cancel after 'start', but before 'done', the background task is executing a task. There is a delay of up to 2 seconds, then the words 'done', 'cleanup', and 'DONE' appear, but the program hangs. If I press Ctrl+C, I get a traceback from the threading module - line 1288, in _shutdown t.join() line 1054, in join self._wait_for_tstate_lock() line 1070, in _wait_for_tstate_lock KeyboardInterrupt So it is waiting for join() to complete. I will continue investigating, but will report it here to see if anyone can come up with an explanation/solution. Thanks Frank -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
On Sunday, February 7, 2016 at 8:04:42 AM UTC+1, Paul Rubin wrote: > Steven D'Aprano writes: > > According to TIOBE, Python's popularity continues to grow: > > http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html > > I wonder how much of that growth is Python 3 and how much is Python 2. > > I'm amazed there's still so much C being done. I meet good programmers > all the time these days, who have never touched C code. > > The crash of Objective-C is amusing ;-). > > It's surprising that R places at all, given the amount of math that its > users need to know. > > I wonder what it means that Perl is booming. Hmm. Nice points: Programming language popularity is generally voodoo. I am only surprised at your surprise at R. Data (science) is after all the hot subject A programmer moving into that field typically starts with python A statistician typically starts R [My voodoo of course :-) ] -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
Am 07.02.16 um 08:04 schrieb Paul Rubin: Steven D'Aprano writes: According to TIOBE, Python's popularity continues to grow: http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html I wonder how much of that growth is Python 3 and how much is Python 2. I'm amazed there's still so much C being done. I meet good programmers all the time these days, who have never touched C code. This is easily explained; C is used a lot in the hardware and embedded field. Compiled C output is nearly as compact as handwritten assembly code, and arguably much more maintainable. C above C++ can be an artifact. The metric uses search engines to ask for "C -c++ -java -python ..." - I'm not sure they can really distinguish between C and C++ this way. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO
Rustom Mody writes: > Data (science) is after all the hot subject > A programmer moving into that field typically starts with python > A statistician typically starts R There aren't THAT many statisticians out there, compared to programmers. -- https://mail.python.org/mailman/listinfo/python-list
Re: asyncio - how to stop background task cleanly
"Frank Millman" : > Alas, I spoke too soon. > > [...] > > If I press Ctrl+C, I get a traceback from the threading module - > >line 1288, in _shutdown >t.join() >line 1054, in join >self._wait_for_tstate_lock() >line 1070, in _wait_for_tstate_lock > KeyboardInterrupt > > So it is waiting for join() to complete. I will continue > investigating, but will report it here to see if anyone can come up > with an explanation/solution. I can't see your complete program, but here's mine, and it seems to be working: #!/usr/bin/env python3 import asyncio, time def main(): loop = asyncio.get_event_loop() try: task = asyncio.async(background_task()) loop.run_until_complete(asyncio.wait([ task, terminator(task) ])) finally: loop.close() @asyncio.coroutine def terminator(task): yield from asyncio.sleep(5) task.cancel() yield from asyncio.wait([ task ]) @asyncio.coroutine def background_task(): try: while True: print('start') time.sleep(2) print('done') yield from asyncio.sleep(10) except asyncio.CancelledError: print('cleanup') print('DONE') if __name__ == '__main__': main() (My Python is slightly older, so replace yield from ==> await @asyncio.coroutine ==> async asyncio.async ==> asyncio.ensure_future) Marko -- https://mail.python.org/mailman/listinfo/python-list