Re: Are all items in list the same?

2019-01-08 Thread ike
On Tue, Jan 08, 2019 at 01:05:09PM +1100, Chris Angelico wrote: > No, because the iteration would never happen. If the list is empty, > a[1:] is also empty, and i==a[0] will never be evaluated. So it is > safe. (But I agree that it's not instantly obvious.) Oh yeah, you're right. I overthought it

Re: Are all items in list the same?

2019-01-07 Thread ike
You might do something like if len(a) == 0 or all(i == a[0] for i in a[1:]): This should be linear complexity and short circuiting and in general it doesn't get much better than this. Though I wouldn't bet there isn't a better (faster/clearer/more readable) solution. On Mon, Jan 07, 2019 at

Re: Asyncio tasks getting cancelled

2018-11-21 Thread ike
Sorry for the latency. On Tue, Nov 06, 2018 at 03:39:24PM -0700, Ian Kelly wrote: > > What I meant was, the error message is specific to futures in the > > 'PENDING' state. Which should be set to 'RUNNING' before any actions > > occur. So it appears the tasks weren't started at all. > > Ah. I don

Re: Asyncio tasks getting cancelled

2018-11-05 Thread ike
On Mon, Nov 05, 2018 at 07:15:04PM -0700, Ian Kelly wrote: > > For context: > > https://github.com/ldo/dbussy/issues/13 > > https://gist.github.com/tu500/3232fe03bd1d85b1529c558f920b8e43 > > > > It really feels like asyncio is loosing strong references to scheduled > > tasks, as excplicitly keeping

Re: Asyncio tasks getting cancelled

2018-11-05 Thread ike
On Tue, Nov 06, 2018 at 12:45:03AM +0100, i...@koeln.ccc.de wrote: > Also, I may be overlooking things, but I haven't found a way to add a > task before calling run_forever(), as asyncio will then say the loop > isn't running yet. So I'm not sure how you would jumpstart in that case. Ok, I was con

Re: Asyncio tasks getting cancelled

2018-11-05 Thread ike
On Mon, Nov 05, 2018 at 01:57:56PM -0700, Ian Kelly wrote: > > Which is what I want in this case. Scheduling a new (long-running) task > > as a side effect, but returning early oneself. The new task can't be > > awaited right there, because the creating one should return already. > > If you want t

Re: Asyncio tasks getting cancelled

2018-11-05 Thread ike
This weird mixing was actually a side effect of me quickly coming up with a small example, sorry for the confusion. I just saw, actually using the same loop gets rid of the behavior in this case and now I'm not sure about my assertions any more. Yet it still looks like asyncio doen'st keep strong r

Asyncio tasks getting cancelled

2018-11-04 Thread ike
Hi all, I'm having trouble with asyncio. Apparently tasks (asyncio.create_task) are not kept referenced by asyncio itself, causing the task to be cancelled when the creating function finishes (and noone is awaiting the corresponding futue). Am I doing something wrong or is this expected behavior?