Re: Queue.Queue-like class without the busy-wait

2005-03-25 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > I started once, using the Timer class in the Threading Module to > break the lock. However the Timer class uses the same kind of > sleep-polling loop, to delay the exection and allow an intermediate > cancel, as the loop that is used in Queue.Queue, so th

Re: Queue.Queue-like class without the busy-wait

2005-03-25 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > > I've never checked this code but it wouldn't have occurred to me that > > Queue uses any kind of timeout loop. Can't it work the obvious way > > with a semaphore? > > And how is this semaphore going to be released if the timeout is > reached? I meant

Re: Queue.Queue-like class without the busy-wait

2005-03-25 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > > I meant a semaphore to synchronize the queue when adding or removing > > objects. > > Last I looked there was a lock used for that. OK, that amounts to the same thing. > The loop is only for when you cant remove or add an element immediatly > and th

Re: Queue.Queue-like class without the busy-wait

2005-03-25 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > Well maybe you could use an os.pipe as a timeout lock then. When the lock is > instantiated you put one byte in it. Aquiring the lock is implemented by > reading one byte, releasing the lock is implemented by writing a byte. > Aquiring the lock with a tim

Re: Save passwords in scripts

2005-03-28 Thread Paul Rubin
Florian Lindner <[EMAIL PROTECTED]> writes: > Can I find out the identity of the client (PID/UID) when using unix socket? Unix sockets have a feature called ancillary messages that lets you do that, but the Python socket module currently doesn't support the feature. There's an open sourceforge b

Re: [Newbie] How do I get better at Python programming?

2005-03-28 Thread Paul Rubin
Anon <[EMAIL PROTECTED]> writes: > I'd like to get to the next level, but I'm not sure how. Are there > any suggestions for continuing to learn? How did you guys learn? I'd say look at some more general computer science books, maybe not Python based. -- http://mail.python.org/mailman/listinfo

Re: Queue.Queue-like class without the busy-wait

2005-03-29 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > Well have a look at what I have written over the weekend. It uses > a seperate thread with one pipe for a wakeup mechanisme. Thanks, I'll look at it. Why don't you use usleep instead of a pipe? I decided over the weekend that using a separate thread wit

Re: Queue.Queue-like class without the busy-wait

2005-03-29 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > I'm not going to call my solution simple, but it wastes very few > cycles. if no thread is blocked on a lock, the select will just > block until that changes. No need for some kind of polling loop. I think I understand. My original idea was to use a hea

Re: Queue.Queue-like class without the busy-wait

2005-03-29 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > > There needs to be a way to send signals to threads, or raise > > asynchronous exceptions in them. There's been some discussion in > > sourceforge about that, but the issues involved are complex. > > Well I have raised this issue before and as far as I

Re: Secure scripts variables

2005-03-30 Thread Paul Rubin
Florian Lindner <[EMAIL PROTECTED]> writes: > I have a script which is readable and executable by a user, but not > writable. > The users executes the scripts, it reads in a value and based on this value > it computes a result and stores it in a variable. > Can the user read out the value of this v

Re: Queue.Queue-like class without the busy-wait

2005-03-30 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > I'm not sure that this would be an acceptable approach. I did the man > semop and it indicates this is part of system V IPC. This makes me > fear that semaphores will use file descriptors or other resources > that are only available in a limited amount. N

Re: Secure scripts variables

2005-03-31 Thread Paul Rubin
Florian Lindner <[EMAIL PROTECTED]> writes: > AFAIK scripts can't be setuid? Can you tell me what you mean and how to do > it? Actually it looks like Linux doesn't support setuid scripts. I thought the feature had been restored. There is a well-known security hole but there are workarounds for i

Re: assignments - want a PEP

2005-03-31 Thread Paul Rubin
"Kay Schluehr" <[EMAIL PROTECTED]> writes: > >>> a = Symbol() > >>> a > a Use a = Symbol('a') instead and it should solve most of the problems you mention. What's supposed to happen anyway, in your proposal, after a = Symbol() b = a print b ? -- http://mail.python.org/mailman/listi

Re: Queue.Queue-like class without the busy-wait

2005-04-01 Thread Paul Rubin
Have you looked at this? A paper about adding asynchronous exceptions to Python. http://www.cs.williams.edu/~freund/papers/02-lwl2.ps -- http://mail.python.org/mailman/listinfo/python-list

Simple thread-safe counter?

2005-04-01 Thread Paul Rubin
I'd like to have a function (or other callable object) that returns 0, 1, 2, etc. on repeated calls. That is: print f() # prints 0 print f() # prints 1 print f() # prints 2 # etc. There should never be any possibility of any number getting returned twice, or getting skipped

Re: Simple thread-safe counter?

2005-04-01 Thread Paul Rubin
Tim Peters <[EMAIL PROTECTED]> writes: > The GIL is your friend here: > > import itertools > f = itertools.count().next Thanks, I was hoping something like this would work but was not sure I could rely on it. > A similar thing can be done with xrange. But either way sucks if you > call

Re: Queue.Queue-like class without the busy-wait

2005-04-01 Thread Paul Rubin
Nick Craig-Wood <[EMAIL PROTECTED]> writes: > I believe futex is the thing you want for a modern linux. Not > very portable though. That's really cool, but I don't see how it can be a pure userspace operation if the futex has a timeout. The kernel must need to keep track of the timeouts. Howeve

Re: Simple thread-safe counter?

2005-04-02 Thread Paul Rubin
Skip Montanaro <[EMAIL PROTECTED]> writes: > How about (untested): > > import Queue > counter = Queue.Queue() > counter.put(0) > def f(): > i = counter.get() > counter.put(i+1) > return i Hmmm, that's a bit messier than I hoped for, but it looks sure to wor

Re: Simple thread-safe counter?

2005-04-02 Thread Paul Rubin
[EMAIL PROTECTED] (Aahz) writes: > This is one case where'd recommend using a plan RLock() instead of using > Queue -- the RLock() will be more efficient... I'm starting to believe the GIL covers up an awful lot of sloppiness in Python. I wonder if there could be a decorator approach: @synch

Re: Simple thread-safe counter?

2005-04-02 Thread Paul Rubin
Tim Peters <[EMAIL PROTECTED]> writes: > If you don't want to exploit it, that's fine: there was always an > obvious approach using an explicit mutex here, and the only thing > stopping you from using it is a desire to be clever. Exploiting the > GIL in CPython is clever; using an explicit mutex

Re: unittest vs py.test?

2005-04-03 Thread Paul Rubin
"Raymond Hettinger" <[EMAIL PROTECTED]> writes: > When writing a large suite, you quick come to appreciate being able > to use assert statements with regular comparision operators, debugging > with normal print statements, and not writing self.assertEqual over and > over again. The generative test

Re: string goes away

2005-04-03 Thread Paul Rubin
"Martin v. Löwis" <[EMAIL PROTECTED]> writes: > Out of curiosity: when thinking about Python 3.0, what is the timespan > in which you expect that to appear? Before 2010? After 2010? After 2020? I'm not terribly worried about Python 3.0 incompatibilities, whenever those are. There are already thre

Re: unittest vs py.test?

2005-04-03 Thread Paul Rubin
"Terry Reedy" <[EMAIL PROTECTED]> writes: > > But assert statements vanish when you turn on the optimizer. If > > you're going to run your application with the optimizer turned on, I > > certainly hope you run your regression tests with the optimizer on. > > I don't see why you think so. Asserti

Re: Python Google Server

2005-04-05 Thread Paul Rubin
[EMAIL PROTECTED] writes: > (This is actually an 'inventive' short term measure to get round a > restrictive internet policy at work :-) If that means what I think, you're better off setting up a url-rewriting proxy server on some other machine, that uses SSL on the browser side. There's one wri

Re: sorting a list and counting interchanges

2005-04-06 Thread Paul Rubin
John Machin <[EMAIL PROTECTED]> writes: > 1. What is an "interchange"? Swapping two elements during the sort. > 2. Without a definition that refers only to to the input and output, > one would have to say that "interchange" implies "event" and so the > number of interchanges would depend on the s

Re: sorting a list and counting interchanges

2005-04-06 Thread Paul Rubin
"Jordan Rastrick" <[EMAIL PROTECTED]> writes: > def mycmp(x,y): >global phase >c = cmp(x,y) >if c > 0: # i.e. a swap will be performed in the sort >phase = -phase >return c That doesn't necessarily work. You don't know that c>0 will always result in a swap. You don't know

Re: sorting a list and counting interchanges

2005-04-07 Thread Paul Rubin
Peter Nuttall <[EMAIL PROTECTED]> writes: > I would just write a quicksort and have a counter in the swap function. > A cunning way to do it would be to multiply the counter by -1 for each > swap. if you want I can write what I had in mind. Wikipedia has a good > article of quicksort. Writing a so

Re: Simple Python + Tk text editor

2005-04-13 Thread Paul Rubin
Jonathan Fine <[EMAIL PROTECTED]> writes: > I'm looking for a simple Python + Tk text editor. > > I want it as a building block/starting point. Something wrong with IDLE? -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Tkinter Question

2005-04-13 Thread Paul Rubin
"Pseud O'Nym" <[EMAIL PROTECTED]> writes: > class App: > def __init__(self, master): > frame = Frame(master) > frame.pack(side=LEFT, fill=Y) > image1 = PhotoImage(file='button_a.gif') > self.button = Button(frame, image=image1) > self.button.pack(side=TOP) > > Can anyone enli

Re: Compute pi to base 12 using Python?

2005-04-13 Thread Paul Rubin
Dick Moores <[EMAIL PROTECTED]> writes: > I need to figure out how to compute pi to base 12, to as many digits > as possible. I found this reference, > , but I really don't > understand it well enough. Could someone show me how to do what I need? Using the G

Re: Compute pi to base 12 using Python?

2005-04-13 Thread Paul Rubin
Dick Moores <[EMAIL PROTECTED]> writes: > I don't believe GNU "bc" is available for Windows, is it? I don't know. It probably works ok under Cygwin at least. -- http://mail.python.org/mailman/listinfo/python-list

Re: A testcase for a Queue like class.

2005-04-15 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > The tube will have an open method, with as argument an > access parameter that will determine if the thread wants > to put things (write) on the queue or will get (read) things > from the queue (or both). Now what I want is that a thread that > opens the

Re: Compute pi to base 12 using Python?

2005-04-17 Thread Paul Rubin
Dick Moores <[EMAIL PROTECTED]> writes: > >C:\cygwin\bin\bc -l > pi12.txt > > But how or when do you enter the lines > > scale = 3000 > obase = 12 > print 4 * a(1) You could put them into a file, say pi.bc. Then run bc -l pi.bc -- http://mail.python.org/mailman/listinfo/python-list

How to run Python in Windows w/o popping a DOS box?

2005-04-19 Thread Paul Rubin
Dumb question from a Windows ignoramus: I find myself needing to write a Python app (call it myapp.py) that uses tkinter, which as it happens has to be used under (ugh) Windows. That's Windows XP if it makes any difference. I put a shortcut to myapp.py on the desktop and it shows up as a little g

Re: How to run Python in Windows w/o popping a DOS box?

2005-04-19 Thread Paul Rubin
[EMAIL PROTECTED] (Bengt Richter) writes: > I would try right-clicking the shortcut icon and selecting > properties, then select the shortcut tab and edit the target string > with s/python/pythonw/ and then click ok. Thanks! I'll try that tomorrow. I never would have figured that out. -- http:/

Re: Why Python does *SLICING* the way it does??

2005-04-21 Thread Paul Rubin
Antoon Pardon <[EMAIL PROTECTED]> writes: > I sometimes think python should have been more explicite here, > using a marker for the start-index and end-index, may '^' and > '$'. So if you wanted the last element you had to write: > > lst[$] > > And for the next to last element: > > lst[$ - 1

Re: Why Python does *SLICING* the way it does??

2005-04-21 Thread Paul Rubin
"Dan Bishop" <[EMAIL PROTECTED]> writes: > Name a problem space that inherently requires arrays to be 1-based > rather than 0-based. "inherently" is too strong a word, since after all, we could do all our computing with Turing machines. Some algorithms are specified in terms of 1-based arrays. A

Re: Why Python does *SLICING* the way it does??

2005-04-21 Thread Paul Rubin
[EMAIL PROTECTED] writes: > > Suppose you could. Then what should > > ([3, 1, 4] indexbase 0) + ([1, 5, 9] indexbase 4) > > equal? > If + means add, the result would be ([4,6,13] indexbase 0) . That's counterintuitive. I'd expect c = a + b to result in c[i] = a[i]+b[i] for all elements. So, fo

Re: How to run Python in Windows w/o popping a DOS box?

2005-04-21 Thread Paul Rubin
[EMAIL PROTECTED] (Bengt Richter) writes: > I would try right-clicking the shortcut icon and selecting > properties, then select the shortcut tab and edit the target string > with s/python/pythonw/ and then click ok. > > Then try double clicking the shortcut icon again. If that does it, > you're

Re: anonymous function objects?

2005-04-28 Thread Paul Rubin
Uwe Mayer <[EMAIL PROTECTED]> writes: > >>> f = {print "hello world"} > >>> f() > hello world > in Pyton? Lambda expressions don't work here. Closest you can come is: f = lambda: sys.stdout.write("hello world\n") Of course if you're trying to capture the function in a named variable like f,

Re: large dictionary creation takes a LOT of time.

2005-04-29 Thread Paul Rubin
"possibilitybox" <[EMAIL PROTECTED]> writes: > this code here: > > > def wordcount(lines): > for i in range(len(lines)/8): > words = lines[i].split(" ") > if not locals().has_key("frequency"): > frequency = {} > for word in words: > if frequenc

Re: Find relative url in mixed text/html

2015-11-27 Thread Paul Rubin
Rob Hills writes: > Note, in the beginning of this project, I looked at using "Beautiful > Soup" but my reading and limited testing lead me to believe that it is > designed for well-formed HTML/XML and therefore was unsuitable for the > text/html soup I have. If that belief is incorrect, I'd be g

Re: Find relative url in mixed text/html

2015-11-28 Thread Paul Rubin
Rob Hills writes: > Personally, I'd rather go with something based on a language I am > reasonably familiar with (eg Python or Java) however it seems the vast > bulk of Forum software is based on PHP :-( It's certainly possible to write good software in PHP, so it's mostly a matter of the design

Re: Catogorising strings into random versus non-random

2015-12-21 Thread Paul Rubin
Steven D'Aprano writes: > Does anyone have any suggestions for how to do this? Preferably something > already existing. I have some thoughts and/or questions: I think I'd just look at the set of digraphs or trigraphs in each name and see if there are a lot that aren't found in English. > - I thi

Re: $5 Campaign - Packt Publishing

2015-12-23 Thread Paul Rubin
gavin.pa...@gmail.com writes: > Packt Publishing is inviting the tech world to explore its extensive... This looks like affiliate spam (shortened link omitted). Direct link: https://www.packtpub.com They do have some good stuff there. -- https://mail.python.org/mailman/listinfo/python-list

Re: Is there an idiom for this?

2015-12-24 Thread Paul Rubin
KP writes: > for config in cfg: > if config != 'c': > print config > > Is there an idiom that combines the 'for...' & the 'if..' lines into one? Maybe you actually want print [config for config in cfg if config != 'c'] That prints all the relevant keys as a list, rather than o

Re: raise None

2015-12-30 Thread Paul Rubin
Steven D'Aprano writes: > def _validate(a, b): > if condition(a) or condition(b): return TypeError > ... > Obviously this doesn't work now, since raise None is an error, but if it did > work, what do you think? Never occurred to me. But in some analogous situations I've caught the exception

Re: We will be moving to GitHub

2016-01-01 Thread Paul Rubin
Zachary Ware writes: > ... the canonical CPython repository will be moving to GitHub in the > near future. Note that we will *not* be using the GitHub issue > tracker or wiki, just the hosting and review/pull request system. Will everyone wanting to submit patches be required to use a Github acc

Re: We will be moving to GitHub

2016-01-01 Thread Paul Rubin
Zachary Ware writes: > Correct, no GitHub account will be required for interactions on the > bugs.python.org tracker, and a patch can move all the way through to commit > entirely on the b.p.o tracker (just as currently). Thanks. -- https://mail.python.org/mailman/listinfo/python-list

Re: We will be moving to GitHub

2016-01-01 Thread Paul Rubin
Terry Reedy writes: > While the decision might not be my personal first choice, we > absolutely need more core developers contributing, including reviewing > contributed patches. Yeah, I'm not delighted by the choice either, but as long as the core devs have bought in and it doesn't affect non-co

Re: GitHub's ³pull request² is proprietary lock-in

2016-01-03 Thread Paul Rubin
Random832 writes: > All of that discussion has value, and it's not good to > have any of it locked up in a place that cannot be exported. I have a dim recollection of Python moving from Trac to a proprietary, hosted bug tracker for a while, but now they're back to an open(?) system but are about

Re: GitHub's ³pull request² is proprietary lock-in

2016-01-03 Thread Paul Rubin
Chris Angelico writes: > If you're not using a GitHub PR, then what you're doing is using GH to > host your repository. So yes, you pull into your local repo and then > push to GH. What's the point of GH in that situation? -- https://mail.python.org/mailman/listinfo/python-list

Re: GitHub's ³pull request² is proprietary lock-in

2016-01-03 Thread Paul Rubin
Chris Angelico writes: > On Sun, Jan 3, 2016 at 9:42 PM, Paul Rubin wrote: >> Chris Angelico writes: >>> If you're not using a GitHub PR, then what you're doing is using GH to >>> host your repository. >> What's the point of GH in that situation?

Re: What is the fastest way to do 400 HTTP requests using requests library?

2016-01-05 Thread Paul Rubin
Steven D'Aprano writes: > Maybe they're stress-testing a web server, or they just want to download > things in a rush. They're stress-testing a web server through a tor proxy? This sounds abusive to me. I also wonder whether 400 referred to the HTTP 400 error code rather than the number of requ

Re: ouvrir python

2016-01-06 Thread Paul Rubin
"Jacques Rosier" writes: > J’ai téléchargé Python 351. Il est dans la liste des applications de > mon ordi (Lenovo; Windows 10). Mais impossible de l’ouvrir. Que faire? Téléchargéz .exe installer https://www.python.org/ftp/python/3.5.1/python-3.5.1-amd64.exe puis cliquez l'.exe pour marcher.

Re: How to remove item from heap efficiently?

2016-01-09 Thread Paul Rubin
"Sven R. Kunze" writes: > Basically a task scheduler where tasks can be thrown away once they > are too long in the queue. I don't think there's a real nice way to do this with heapq. The computer-sciencey way would involve separate balanced tree structures for the two sorting keys (think of a d

Re: How to remove item from heap efficiently?

2016-01-11 Thread Paul Rubin
srinivas devaki writes: > I googled about "timing wheels" and "Linux kernel scheduler" Sorry, correct term was "timer wheel" rather than "timing wheel". http://www.elinux.org/Kernel_Timer_Systems has some links. The Erlang BEAM internal scheduler works the same way, iirc. -- https://mail.pyth

Re: Keen eyes

2016-01-16 Thread Paul Rubin
Steven D'Aprano writes: > And this is the language that 95% of the Internet uses... my brain hurts. WAT. https://www.youtube.com/watch?v=20BySC_6HyY -- https://mail.python.org/mailman/listinfo/python-list

Re: How to simulate C style integer division?

2016-01-21 Thread Paul Rubin
Ben Finney writes: > I'm not sure I know exactly what behaviour you want (“C style” may mean > different things to each of us). I thought he meant trunc-division, so -5 / 2 = -2 and -5 % 2 = -1. Python specifies floor division but C leaves it unspecified, I thought. -- https://mail.python.org/ma

Re: Question about asyncio and blocking operations

2016-01-25 Thread Paul Rubin
Marko Rauhamaa writes: > Note that neither the multithreading model (which I dislike) nor the > callback hell (which I like) suffer from this problem. There are some runtimes (GHC and Erlang) where everything is nonblocking under the covers, which lets even the asyncs be swept under the rug. Simi

Re: psss...I want to move from Perl to Python

2016-01-28 Thread Paul Rubin
Fillmore writes: > I look and Python and it looks so much more clean Yes it is, I forgot everything I knew about Perl shortly after starting to use Python. > add to that that it is the language of choice of data miners... There are a bunch of statistical libraries and that sort of thing but

Re: The computer that mastered Go

2016-01-29 Thread Paul Rubin
mm0fmf writes: > Is it written in Python? One would expect it to be written in Go, but it turns out to be C++ and Lua :(. -- https://mail.python.org/mailman/listinfo/python-list

Re: psss...I want to move from Perl to Python

2016-01-31 Thread Paul Rubin
Rustom Mody writes: > I would guess it needs more recoding than explicit compilation! > Maybe something like http://www.colm.net/open-source/ragel/ > Unfortunately no python binding so far :-( Neat, that looks kind of like lex/flex but with more backends. -- https://mail.python.org/mailman/listi

Re: psss...I want to move from Perl to Python

2016-01-31 Thread Paul Rubin
Cameron Simpson writes: > Adzapper. It has many many regexps matching URLs. (Actually a more > globlike syntax, but it gets turned into a regexp.) You plug it into > your squid proxy. Oh cool, is that out there in circulation? It sounds like the approach of merging all the regexes into one and c

Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-06 Thread 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 a

Re: [STORY-TIME] THE BDFL AND HIS PYTHON PETTING ZOO

2016-02-06 Thread Paul Rubin
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-lis

Re: modifying a standard module?

2016-02-12 Thread Paul Rubin
Ulli Horlacher writes: >> tarfile.TarFile.extractall = new_extractall > > This is more easy than I could imagined :-) It is in my Python notes, > now. This is called "duck punching" or "monkey patching" and sometimes it's necessary, but it's something of an antipattern since the module could chan

Re: asyncio - run coroutine in the background

2016-02-14 Thread Paul Rubin
"Frank Millman" writes: > The benefit of my class is that it enables me to take the coroutine > and run it in another thread, without having to re-engineer the whole > thing. Threads in Python don't get you parallelism either, of course. I haven't used async/await yet and it's looking painful.

Re: asyncio - run coroutine in the background

2016-02-17 Thread Paul Rubin
Marko Rauhamaa writes: > @asyncio.coroutine > def background_task(): ... > while time.time() - t < 10: > pass Wait, that's a cpu-busy loop, you can't do that in cooperative multitasking. Of course you need a wait there. -- https://mail.python.org/mailman/listinfo/python-list

Re: Guido on python3 for beginners

2016-02-17 Thread Paul Rubin
Steven D'Aprano writes: > I suppose that it is objectively correct that it is harder to learn > than Python 2. But I don't think the learning curve is any steeper. If > anything, the learning curve is ever-so-slightly less steep. I think py3 has more learning curve because it uses iterators in pl

Re: How the heck does async/await work in Python 3.5

2016-02-19 Thread Paul Rubin
Rustom Mody writes: > Forgot the probably most important: Not merging stackless into CPython I thought there was some serious technical obstacle to that. Where can I find Greg Ewing's suggestions about Python coroutines? The async/await stuff seems ok on the surface. I liked the Lua paper abou

Re: asyncio - run coroutine in the background

2016-02-19 Thread Paul Rubin
Marko Rauhamaa writes: > "Frank Millman" : >> I would love to drive the database asynchronously, but of the three >> databases I use, only psycopg2 seems to have asyncio support. > Yes, asyncio is at its infancy. There needs to be a moratorium on > blocking I/O. Unfortunately there appears to be

Re: asyncio - run coroutine in the background

2016-02-20 Thread Paul Rubin
Marko Rauhamaa writes: > It would appear that disk I/O is considered nonblocking at a very deep > level: > * O_NONBLOCK doesn't have an effect > * a process waiting for the disk to respond cannot receive a signal > * a process waiting for the disk to respond stays in the "ready" state You can

Re: How the heck does async/await work in Python 3.5

2016-02-20 Thread Paul Rubin
Steven D'Aprano writes: > "But frankly the stuff I'm seeing in this thread makes me sad for > *literally every programming language in existence except for Erlang > and maybe one or two others*, which altogether about six people use in > total..." Erlang microtasks are more a matter of the runtim

Re: Make a unique filesystem path, without creating the file

2016-02-22 Thread Paul Rubin
Chris Angelico writes: >> I was under the impression that the point of UUIDs is that you can be >> *so* confident that there won't be a collision that for all practical >> purposes it's indistinguishable from being certain. > Maybe, if everyone's cooperating. I'm not sure how they fare in the > fa

Re: Make a unique filesystem path, without creating the file

2016-02-22 Thread Paul Rubin
Marko Rauhamaa writes: >> http://www.2uo.de/myths-about-urandom/ > Did you post the link because you agreed with the Web pamphlet? I don't know what web pamphlet you mean, but the right thing to use now is getrandom(2). The random/urandom interface was poorly designed and misleadingly documented

Re: Make a unique filesystem path, without creating the file

2016-02-22 Thread Paul Rubin
Marko Rauhamaa writes: http://www.2uo.de/myths-about-urandom/ >> I don't know what web pamphlet you mean, > The only one linked above. Oh, I wouldn't have called that a pamphlet. I could quibble with the writing style but the points in the article are basically correct. > getrandom(2) is a

Re: Make a unique filesystem path, without creating the file

2016-02-22 Thread Paul Rubin
Steven D'Aprano writes: > https://www.python.org/dev/peps/pep-0506/ I didn't know about this! The discussion was all on mailing lists? A few things I suggest changing: 1) the default system RNG for Linux should be getrandom(2) on kernels that support it (3.17 and later). 2) Some effort

Re: Make a unique filesystem path, without creating the file

2016-02-22 Thread Paul Rubin
Chris Angelico writes: > How much future are you expecting? This is old but its methodology still seems ok: http://saluc.engr.uconn.edu/refs/keymgr/blaze95minimalkeylength.pdf I also like this: http://cr.yp.to/talks/2015.10.05/slides-djb-20151005-a4.pdf Quote (slide 37): The crypto us

Re: Make a unique filesystem path, without creating the file

2016-02-22 Thread Paul Rubin
Marko Rauhamaa writes: > It is also correct that /dev/urandom depletes the entropy pool as > effectively as /dev/random. I think see what's confusing you: the above is a misconception that is probably held by lots of people. Entropy is not water and from a cryptographic standpoint there is esse

Re: Make a unique filesystem path, without creating the file

2016-02-23 Thread Paul Rubin
Mark Lawrence writes: > https://mail.python.org/pipermail/python-ideas/2015-September/036333.html > then http://www.gossamer-threads.com/lists/python/dev/1223780 Thanks. It would be nice if those were gatewayed to usenet like this group is. I can't bring myself to subscribe to mailing lists. >

Re: How to read from a file to an arbitrary delimiter efficiently?

2016-02-24 Thread Paul Rubin
Steven D'Aprano writes: > while b: > buffer.append(b) This looks bad because of the overhead of list elements, and also the reading of 1 char at a time. If it's bytes that you're reading, try using bytearray instead of list: def chunkiter(f,delim): buf = bytearray()

Re: [Off-topic] Requests author discusses MentalHealthError exception

2016-02-29 Thread Paul Rubin
Ben Finney writes: >> "All that he had learned" meaning his delusions and psychoses? > Indeed. If a revelation is unconnected to reality, it's misleading to > say that one has “learned” it > When someone describes the ill effects their mental illness produced, I > find it rather condescending

Re: Inception

2016-03-02 Thread Paul Rubin
Ben Finney writes: > I'm familiar with that document. It doesn't help me understand what you > mean by “embed CPython in CPython”. It seems straightforward enough to me. Lots of Python programs load C extensions. Denis is asking whether one of those C extensions could itself embed CPython throu

Re: context managers inline?

2016-03-10 Thread Paul Rubin
Jussi Piitulainen writes: > return ModeIO(f.read()) These suggestions involving f.read() assume the file contents are small enough to reasonably slurp into memory. That's unlike the original where "load" receives a stream and might process it piecewise. -- https://mail.python.org/mailma

Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

2016-03-13 Thread Paul Rubin
BartC writes: > def case(*args): > return any((arg == switch.value for arg in args)) def case(values): return switch.value in values > I used it in my benchmark to replace the if-else chain checking three > lots of ranges: > > switch(c) > if case(ord("A"),ord("B"),ord("C"),ord("D"),ord(

Re: How to waste computer memory?

2016-03-20 Thread Paul Rubin
Chris Angelico writes: > You can pretend that only 1 and 0 are enough. Good luck making THAT work. YOU had ONES??? Back in the day, my folks had to do everything with just zeros. -- https://mail.python.org/mailman/listinfo/python-list

Re: Convert list to another form but providing same information

2016-03-21 Thread Paul Rubin
Maurice writes: > I have a list such [6,19,19,21,21,21] > Therefore the resulting list should be: > [0,0,0,0,0,0,1,0,0,0...,2,0,3,0...0] Rather than a sparse list you'd typically want a dictionary (untested): from collections import defaultdict the_list = [0,0,0,0,0,0,1,0,0,0...,2,0,3,0...0]

Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-25 Thread Paul Rubin
Steven D'Aprano writes: > Culturally, C compiler writers have a preference for using undefined > behaviour to allow optimizations, even if it means changing the semantics > of your code. If your code has UB then by definition it has no semantics to change. Code with UB has no meaning. -- https:

Re: repeat items in a list

2016-03-26 Thread Paul Rubin
beliav...@aol.com writes: > yy = list(chain.from_iterable([list(repeat(aa,nrep)) for aa in xx])) The chain approach seems more natural to me: yy = list(chain.from_iterable(map(lambda x: [x,x], xx))) may make the doubling more obvious, and in Python 3 it should avoid the intermediate lists sinc

Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Paul Rubin
Steven D'Aprano writes: > For example, would you consider that this isolated C code is > "meaningless"? > int i = n + 1; It's meaningful as long as n is in a certain range of values so there's no overflow. > But according to the standard, it's "meaningless", since it might > overflow, and signed

Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Paul Rubin
BartC writes: > But my suggestion was to have required a keyword in front of > such expressions. Should there be a keyword in front of a line containing "sqrt(x)" ? What about "launch(missiles)" ? The compiler can't tell which of those expressions has a side effect. The first might be buggy cod

Re: Undefined behaviour in C [was Re: The Cost of Dynamism]

2016-03-26 Thread Paul Rubin
Rustom Mody writes: > eg haskell (ghc) is written in ghc > Where did the first bootstrap start from? The very earliest Haskell implementation was written in Lisp. -- https://mail.python.org/mailman/listinfo/python-list

Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-27 Thread Paul Rubin
Steven D'Aprano writes: > if condition: > print(1) > print(2) > else: > print(3) > print(4) > what value should it return? Justify your choice. It could whatever value that the last call to print() returns. Lisp has worked like that since the 1950's. > What should be the return

Re: Statements as expressions [was Re: Undefined behaviour in C]

2016-03-28 Thread Paul Rubin
BartC writes: > With more recent ones I've dropped that model, so that statements and > expressions are different, and that is strictly enforced. This makes > implementation simpler, and detects lots more errors. You should try Haskell, where there are only expressions, but the ones that perform

Re: GUI toolkit(s) status

2014-11-20 Thread Paul Rubin
wxjmfa...@gmail.com writes: > Today, there are simply no more valid and working > GUI toolkit running "out of the box". Tkinter still works for me. What's the problem? -- https://mail.python.org/mailman/listinfo/python-list

Re: GUI toolkit(s) status

2014-11-20 Thread Paul Rubin
Terry Reedy writes: > Tcl/Tk currently use UCS-2, which only handles BMP chars. Alternatives > to support astral chars: [other encodings] I haven't looked into the issue but from Christian's post it sounded like the BMP limitation was deeper inside Tcl/TK and would take more serious work to fix.

Re: Searching through more than one file.

2014-12-28 Thread Paul Rubin
Seymore4Head writes: > How can I modify the code to search through a directory of files that > have different filenames, but the same extension? Use the os.listdir function to read the directory. It gives you a list of filenames that you can filter for the extension you want. Per Mark Lawrence,

Re: Searching through more than one file.

2014-12-28 Thread Paul Rubin
Dave Angel writes: > res = set() > fnames = glob('*.txt') > for line in fileinput.input(fnames): > res.update(line.rstrip().split()) > print sorted(res) Untested: print sorted(set(line.rstrip().split() for line in fileinput(fnames))) -- https://mail.python.org/mailman/listinfo/python-list

Re: Comparisons and sorting of a numeric class....

2015-01-09 Thread Paul Rubin
Chris Angelico writes: > for instance, I might have a socket object, and I might not, so I can > use "if not self.socket: self.connect()" ... This sounds like you want a Maybe or Option object. Marko's suggestion rv = f() if rv is not None: return rv rv = g() if rv is no

<    9   10   11   12   13   14   15   16   17   18   >