« first day (3190 days earlier)      last day (1982 days later) » 

01:04
hey guys
i'm using asyncio library in python
i want to create a function which is not blocking the code
even program don't care about it's future result
i have used asyncio.create_task(check_hour_satisfaction(body, properties))
but still i don't understand it usage
 
1 hour later…
02:15
i want to code something like tabletamer.com, basically a program that detects/hooks into specific poker program windows and allows you to use hotkeys, etc. to interact with the gui
is this possible in python or do i need to do it in something like java or c++
02:46
morning cabbage pythonistas
cbg @DeveshKumarSingh
Anyone knows the difference between django.contrib.staticfiles.storage.staticfiles_storage(url) and django.templatetags.static.static(url)? As far as I know, both allow you to get the url of an static file. Which is better?
@underscore What didn't you understand in that? From what I see ,whenever you start the event loop, whatever function you pass on to the create_task runs and stops
@RobertCalove It should be possible, but I am not sure what you mean by detects/hooks into? Does the program windows expose any endpoint/api for those hotkeys etc
hm, idts
i'm wondering if there's some way to do it natively in windows or something. i don't have a full understanding of what's possible
its able to resize windows, and use hotkeys in order to perform actions on the gui that the cursor is hovering over
02:58
Okay, so you mean some sort of web browser automation, did you look at selenium-python.readthedocs.io
@DeveshKumarSingh
async def on_message(channel, body, envelope, properties):

    send_ack_task = asyncio.create_task(send_ack(channel, envelope))
    check_hour_satisfaction_task = asyncio.create_task(check_hour_satisfaction(body, properties))

    await send_ack_task
    await check_hour_satisfaction_task
await channel.basic_consume(on_message, queue_name='btsQ')
i want to run send_ack and check_hour_satisfaction asynchronously
hm, it's not a web browser application afaik
it's a program that's installed on windows, etc.
@RobertCalove okay you linked to a web page hence I assumed as such, I also found pywinauto.github.io
the name of the client is called ignitioncasino.eu
or rather that's the site where the program is
@underscore If your code is longer than about 12 lines, use an external paste tool such as dpaste.com, also see the first starred message on the right
03:05
nice, this might be what i need
this is the entire code
Can you reduce this to an MVCE ? to make it easier to run and debug while keeping the behaviour intact
i'll explain the behavior
is that okay ?
1) it's consume data from mq
2) after consume there will be two tasks
3) 1 = sending ack to message queue
yes, but along with that, an MVCE will work great, I would also strip down the db connections from the code to make it shorter
03:10
4) 2 = run check_hour_satisfaction function
Half your imports are unused @underscore - please produce an mvce
My main point was try to remove the other functions in your code which works, strip it down to the bare minimum of what you want to do and is not working and then show it to me
That's the whole point of an MVCE
okay wait
please check this
Okay so you mentioned what is expected from the program, but can you tell me what you see instead
configparser, json, pymysql, os.path, sys, argparse, time, binascii, os are imported and unused @underscore
 
2 hours later…
05:20
@ParitoshSingh, anky_91 et al: Re the Finding counts of relative and absolute fluctuations in dataframe where each row contains a timeseries: I did major edits on the question; also see my answer which improves on yours by using separate dataframes with one shared ID index which gives much cleaner code...
...It's so much cleaner to keep the damn timeseries separate from their metadata, then you can properly use .apply, .agg, .mean and so on. Also, just because the OP kept calling their timeseries values "dates", doesn't mean you had to... that was your first code smell that their deduplication was exacerbating the problem. In pandas you should generally never need to be passing around lists of column-indices... that's a smell that merge/join/separate dfs with shared indices should be used.
But anyway your answer shows a lot of hard work. 2/3 of the problem there was understanding what the OP meant, their original question statement was circular and repetitive without actually defining their terms ("We count 'spikes' as follows... estimate a threshold... the threshold is what determines what is/isn't a 'spike'..."). I had to rewrite their question statement just for clarity and brevity.
@krijan Guys see my question rewrite and answer, as self-cited above ^^. My one-line response is that when we do decide an unclear but worthy pandas question is good, it's not enough to "Question can only be deciphered by reading the answer's code and discussion." is worrying antipattern, it means the question is indecipherable without this, and hence not reusable resource.
So, do a question rewrite. Again, only when you decide a question is interesting, new and unique. And if the OP can be gently led to providing a MCVE. For all else, downvote and/or close and leave improvement suggestion comments to OP if they seem redeemable.
@AndrasDeak Done, or at least we all collectively fixed the OP's question statement (and MCVE).
06:14
in callback of consume async function i have to run two tasks asynchronously
1) send ack
2) run inbuilt function
how could i achieve that ?
send ack is already async function by aioamqp.readthedocs.io
06:50
what you have should work, it's also defined in the docs in the last example
@DeveshKumarSingh i dont want to await for send ack
cause there are so many incoming messages 400/s
closed
I am trying to install uWSGI on windows 7. But it's failing.
<Check the history to know full error>
The error I am getting says os has no attribute uname
Note: Python version is 3 and os is windows 7
07:06
Thanks
Hey @AndrasDeak
hey martijn
i saw you have replied to a async library questions in SO
i have a question about rabbitmq and async library usage
what i want is to run two tasks asynchronously
1) send ack to message queue
2) run own calculation function
i dont want to await to proceed to 2nd
async def on_message(channel, body, envelope, properties):

    print(f'ack send {envelope.delivery_tag}')
    await channel.basic_client_ack(envelope.delivery_tag)

    asyncio.create_task(check_hour_satisfaction(body, properties))
check_hour_satisfaction
this is my 2nd method
on_message is callback for rabbitmq consume
do you have any suggestion ?
the library i'm using for rabbitmq
07:26
Please read the room rules
Don't ping (@username) users unsolicited. Use pings when they assist the flow of existing conversations.
sorry for that
if anyone can answer my question it will be really helpfull
07:40
re-cabbage
Am I dreaming, or there also was a U9-Forward?
@U10-Forward ?
@ReblochonMasque No i changed my name
haha, the unstoppable progress to moar... :D
Congratulations on the upgrade then @U10-Forward ;)
@ReblochonMasque Haha lol
@underscore you already do... do you want to run the two concurrently? use asyncio.gather, then
if you don't care about them finishing before moving on, launch them with asyncio.ensure_future
async def on_message(channel, body, envelope, properties):

    print(f'ack send {envelope.delivery_tag}')
    asyncio.ensure_future(channel.basic_client_ack(envelope.delivery_tag))

    asyncio.create_task(check_hour_satisfaction(body, properties))
@MisterMiyagi is that ?
07:49
ensure_future and create_task do practically the same
there's no point using both if you have create_task available
async def on_message(channel, body, envelope, properties):
    asyncio.ensure_future(channel.basic_client_ack(envelope.delivery_tag))
    asyncio.ensure_future(check_hour_satisfaction(body, properties))
just try it and report back if it doesn't work
I cannot test it without an MCVE
check_hour_satisfaction don't have return
since it's calling several other functions
@MisterMiyagi P.S. it's a minreprex now :P
@U10-Forward I'm a rebel
plus, I finally have the muscle memory not to write MVCE :D
07:57
@MisterMiyagi how do i catch ensure_future ?
later maybe
@underscore catch?
@underscore well, that may be so, but there are probably tons of other things relevant to your problem you haven't stated here
i mean in future how do i get that value
so just try it and see whether it works
i mean if check_hour_satisfaction return anything in future how do i get that value
do it have callback ?
time travel perhaps
07:58
if you are on 3.7 you don't but use tasks instead
listener ?
@underscore it has a documentation: docs.python.org/3/library/asyncio-future.html
apparently, you can just await it
 add_done_callback(callback, *, context=None)
@MisterMiyagi Haha lol
import asyncio
import aioamqp
import writeToDb

async def connectToMq():
    await aioamqp.connect()

def calculate():
    return 2*4

def callback():
    send_ack()
    processIt()

def processIt():
    result = await calculate()
    writeToDb(result)

async def main():

    channel = connectToMq()
    await channel.consume(callback)

asyncio.run(main())
@MisterMiyagi
this is MVCE
08:10
Why are you hassling people over this?
Yeah man, don't troll newbies
08:28
@U10-Forward seriously?
08:47
I just don't understand why my responsive, collapsible sidebar won't work properly. I cargo-culted all the CSS I could find to the letter. I blame the author.
you need better sticks to wave at the runway
That must be it, something must have fallen into the grass
@underscore no, it's not. The most basic sync/async def and calls are wrong. I have no idea what is writeToDb either.
an attempt was made
you can't have NameErrors if you have ModuleNotFoundErrors
Aha, why did I forget about the wise Should I blame caching? Delivery complete.
08:54
apt for a web-browser
apt-get?
cbg
never seen 5 in a row before. :)
@AndrasDeak I meant to say that clearing cache is "apt' for a web browser
so...apt-get clean?
groan :P
Had to help a guy log in to an hpc cluster today. He uses windows. I still don't know how windows people cope with putty and the like.
09:18
oh, i used putty once. i had no idea what was going on, so i suppose that helps.
@AndrasDeak yes, lets go with that
@AndrasDeak from my experience, badly
of course we ended up finding a linux machine when login wouldn't work...
09:28
I suffer through Windows/Putty all the time for work
/me cries
Soon I will no longer need to support some old legacy Windows systems and I won't look back
must be liberating when it happens
I've got my linux distro ready to roll the second I get the word
Kali, I hope (⌐■_■)
Nah, I'm a filthy mainstreamer
Ubuntu
the gateway drug, as one of my friends put it
09:44
I've tried smoking a bit of Arch, but I didn't like the hangovers it gave
I also tried the harder stuff but ended up back with ubuntu
ol' reliable
import asyncio
import time

async def asyncFn():
    print(f"finished asyncFn at {time.strftime('%X')}")
    return time.sleep(1)

async def nonAsync():
    print(f"finished nonAsync at {time.strftime('%X')}")
    return 12

async def main():

    task1 = asyncio.create_task(asyncFn())
    task2 = asyncio.create_task(nonAsync())

    await asyncio.gather(task1, task2)

asyncio.run(main())
result
finished asyncFn at 15:21:41
finished nonAsync at 15:21:42
i want do run both asyncFn and nonAsync at same time
async def nonAsync(): seems like an oxymoron to me
And wouldn't asyncFn have to await asyncio.sleep or something? I have no idea about async but that looks a bit fishy.
09:59
import asyncio
import time

async def asyncFn():
    print(f"finished asyncFn at {time.strftime('%X')}")
    return time.sleep(1)

def nonAsync():
    print(f"finished nonAsync at {time.strftime('%X')}")
    return 12

async def main():

    asyncio.create_task(asyncFn())
    nonAsync()

asyncio.run(main())
@Arne Canonical did give me a bit of a scare at one point
When they were just firing out data to various third parties willy nilly
@Erfan too new for cv-pls, please read what I linked for you weeks ago
@OldTinfoil yup
that's why I use debian
@OldTinfoil did they?
yup
about the same time they removed the ubuntu manifesto from the face of the Earth
10:14
I remember being weirded out by the search suggestions fetched from the internet .. back in trusty, ironically.
@AndrasDeak it's not this?
not sure, it's been years since I last looked into it
I think I read micahflee.com/2013/01/why-im-leaving-ubuntu-for-debian and footnotes/updates therein
@underscore you do a time.sleep(1) which is not async
use asyncio.sleep(1) if you want to sleep asynchronously
and not block the entire event loop
@AndrasDeak not completely through, but that's a good read. bug #1 is a nice TIL, and it already contains some of the philosophy that obviously went away at some point
> Non-free software leaves users at the mercy of the software owner and concentrates control over the technology which powers our society into the hands of a few.
Kef
Kef
10:58
> bug 1

At least I don't have to `--tc-heuristic-recover` my mariadb server t osnap it out of a halted transaction half of the time I reboot my Windows machine =)
11:21
Cabbage
12:10
I see, just read it. My bad @AndrasDeak
12:20
Yesterday I had an idea for a fun 45 minute project involving constructing a mesh representing the intersection of arbitrary polygons, and in fact it turns out that this is not something you can do in 45 minutes
When I google how to do something and the only relevant result is
1. A pdf
2. On a .edu site
3. with "siggraph" in the title
Then I know that I'm in extreme danger
Bonus points to mcs.csueastbay.edu/~tebo/papers/siggraph90.pdf for fulfilling all that and also only getting me halfway to the solution, since I still don't know how to get from a binary space partition to a mesh
12:42
cbg
Any alternates for hough transform for line detection?
<cricket, cricket>
I'm guessing you'll have to try The Google
12:57
Change my mind: there are no CV experts in the world, only programmers who have been handed a collection of scanned documents with 15 degree skews and need to rotate them into a consistent alignment by Friday.
@Kevin the real world value can go upto 16 degrees. there, mind changed.
The state of the art in computer vision is driven forward by developers who have to invent groundbreaking techniques or else spend 40 hours a week identifying edges manually
You can never find anyone with comprehensive knowledge about alternatives to hough transforms because anyone that successfully employed an alternative is now at the bar trying to forget the experience
Hough about that
I hate it that Hough is one of those words that might be pronounced in 4 different ways but I'm too lazy to look up the correct one
Without looking up, is it pronounced "How", as in Slough?
en.wiktionary.org/wiki/hough says it sounds like /hɒk/ aka "hock" and I'm skeptical of this to the point that I think someone may have vandalized the page as a prank
I would have guessed it was pronounced like hew aka hue aka /hju/
13:04
Hough off. If so, the English language is official broken
@Kevin I think that would also be acceptable
@Kevin /hju/ was not on my list of suspects
@wim done
Worst pronunciation guide ever: "borough (like a in above)"
wim
wim
thx sir deaksalot
13:07
Is that like the American "boro"? The English "above"? breaks down and cries
well any English pronounciation guide without IPA notation is doomed
Google says it's pronounced like "huhf" which is less insane
My initial /hju/ assumption probably comes from my misremembering of Howard Hughes's name as "Howard Houghs"
@Kevin initial revision: /hɒk/, /hɒx/. If it's a prank someone's playing the long game.
@Kevin, there is a glitch in the entry box in the chatroom: upon resizing it (in chrome), it extends beyond the bottom boundary of the browser, and the handle becomes inaccessible - I think the correct behavior should be that upon extension, the entire box remains visible.
get to it, Kevin
13:15
HA! It is not Kevin that manages the chatroom?
disable the noob indicator on main while you're at it :P
Alas, I don't have any affiliation with the SO dev team, so there isn't anything I can do about it.
I'm a Room Owner, which is a role more akin to a moderator than a developer
the sad truth is that we don't own any of the stackoverflow.com domain
Yes, okay - sorry about that! :-)
I was going to say that SO employee balpha is ostensibly in charge of chat features but I see that he left the company in March 2019. Based on how much love chat gets from the company (i.e. none) I'm guessing we're now adrift with no captain.
13:19
wow, didn't know that
Me neither, until one minute ago.
one minute silence...
13:58
does anyone know whether the socket.socket context manager only calls .close or also .shutdown? the docs are vague
@AndrasDeak Growing up, some friends from our church owned a chain of bakeries, named Hough Bakeries. The name was pronounced "huff", similar to the "rough"->"ruff", or "ghoti"->"fish"
At reddit.com/r/CasualUK/comments/63zasy/…, the consensus among people that actually know someone with Hough as a surname is: "h(o|u)ff"
I am conveniently ignoring everyone suggesting "how" because no true hough-knower would say such a thing
Hi all! Is there anybody who works with swagger/flasgger in python?
Never heard of it.
14:07
it is tool for REST API documentation
Challenge: How do I choose 3 identically distributed random integers from 1 to 100 whose sum equals 100?
import random

def random_sum():
    nums = [random.randint(0, 100) for _ in range(3)]
    while sum(nums) != 100:
        nums  = [random.randint(0, 100) for _ in range(3)]
    return nums

random_sum()
# [39, 45, 16]
^ There has to be a better way.
what do you consider "n identically distributed random integers" to begin with? chosen from the same random distribution?
Proposal: Generate three floats in [0,1) via random.random(). Multiply each one by 100/sum(reals). convert to int. If their sum is 101 or 99, choose one at random and add or subtract as necessary.
does selecting two and calculating the last count?
it cannot be chosen randomly given the first two
@Kevin that is what I actually did, except I chose the last one.
14:19
I'm worried that this is the Bertrand Paradox in disguise and you're not going to get an objectively even distribution unless you very very strictly define what an "even distribution" is
@MisterMiyagi If you choose two at random the third is not random (as you've said). In this scenario, the expected value of both of those numbers will be close to 50 and their sum close to 100. Even if we constrained them to be less than 100 somehow, the third will be biased less than the first two in order to shoehorn the sum to be less than 100.
it seems more proper to randomly select from all permutations of {x, y, 100-x-y | x+y < 99}
that is a useful thought
If you take all triplets of integers that add up to 100 and visualize them as points in 3d space, then they all lie on the surface of a single equilateral triangle. So I suspect you can reduce the problem to two dimensions.
that depends on whether you consider ordering, I guess
you have two dimensions for x, y plus one dimension for permutations
14:28
you can definitely use a 2d distribution but it will be highly non-trivial (non-uniform)
If you know a way to choose a random point within an equilateral triangle in 2d space, then you can map it onto the desired triangle in 3d space and get its triple.
you can reverse-engineer the distribution from the permutation approach which might give you a hint...
user10984358
other than this answer is glob like updated now to handle specific file types?
user10984358
118
A: Python glob multiple filetypes

user225312Maybe there is a better way, but how about: >>> import glob >>> types = ('*.pdf', '*.cpp') # the tuple of file types >>> files_grabbed = [] >>> for files in types: ... files_grabbed.extend(glob.glob(files)) ... >>> files_grabbed # the list of pdf and cpp files Perhaps there is another w...

@Kevin "random point", devil in the details as always
14:32
But, hmm, integer lattice points on the 3d triangle might not map to integer lattice points on the 2d triangle, so maybe this is only an appropriate solution if you are fine with real triples rather than integer triples
For real triples you can generate three numbers and rescale to 100
@TheNamesAlc glob only cares about file names, it has no concept for file types
Though I guess that doesn't generally ensure uniformity either
other than name extensions, of course
user10984358
so there is no any way other than concatenating multiple globs?
user10984358
14:35
or any other module? also is itertools.iglob needed as one of the answers suggest?
glob is based on fnmatch which is rather limited: docs.python.org/3/library/fnmatch.html#fnmatch.fnmatch
for complex matching, use regular expressions
user10984358
I just want all images in a folder (jpg png etc)
user10984358
if its of any use, the only non image file is my python file
Which answer says that iglob is "needed"?
use os.scandir and filter .py files
user10984358
14:39
@Kevin it doesn't necessarily say it is needed, but this is the first time I am hearing of a lazy version of glob, I assumed that many functions like imap for instance had its default turned to the lazy version, thought that would be the case with glob
glob does practically the same, just filtering everything not matched by your pattern
user10984358
alright I will try that, is using glob and removing the py file considered bad?
user10984358
I just feel like making the glob call for each specific type seems just odd to me
it is mostly redundant since it means you are not using glob at all
user10984358
in the aspect of learning something new I will try to use os.scandir and fnmatch
user10984358
14:42
thanks a bunch!
Interesting
import pandas as pd

i, j = zip(*[(i, j) for i in range(1, 10) for j in range(1, 10) if i + j <= 10])
pd.value_counts(i)

# 1    9
# 2    8
# 3    7
# 4    6
# 5    5
# 6    4
# 7    3
# 8    2
# 9    1
# dtype: int64
don't use fnmatch, it has the same restriction as glob
user10984358
alrighty
@piRSquared you also have to think about what you want an ordered sample or not
a regular string comparison is fine, e.g. filename.endswith(".py")
14:44
Is (1,4,5) the same as (5,1,4)?
@MisterMiyagi .endswith!
@AndrasDeak I assumed those would be differrent
@AndrasDeak looks innocently
you better :P
user10984358
you guys know python like the back of your hands
@TheNamesAlc I don't really know the back of my hands
user10984358
14:45
can you post the previous one as well
there is no previous one. Do go on. nothing to see here...
user10984358
@piRSquared well uhm in that case back of the guy sitting in front of you :p
user10984358
@MisterMiyagi :/ fine :)
it was filename[-3:] == ".py", but don't tell anyone
user10984358
lol, I just realized I could see edit history, but thanks anyway
user10984358
14:51
list(filter(lambda x:x.endswith('.py'),a))
user10984358
should I use this or is list comprehension better?
comprehensions are preferable
user10984358
[x for x in a if x.endswith('py')]
My rule of thumb is: don't use filter if you have to write a lambda.
user10984358
can you say when is filter preferred?
user10984358
14:51
that answers it
use a generator expression if you don't actually need a list
user10984358
same as your suggestion with map I presume? idk if you remember telling me that :)
plus list(filter()) is one more call
and you want to exclude the .py files, not include them
user10984358
my bad, yeah I want to exclude them
14:52
(x for x in os.scandir(whatever) if not x.endswith(".py"))
Note that the converse is not true: I do not endorse the statement "use filter if you can do so without writing a lambda".
at least on CPython, filter+lambda is faster
I almost never use filter at all, really
in case you really need those few ns :D
(which is practically never)
In the specific case of filtering filenames so you can do IO on the remaining files, I think those nanoseconds are very unlikely to be the performance bottleneck in the program
user10984358
14:56
>>> [x for x in os.scandir('.') if not x.endswith('py')]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
AttributeError: 'posix.DirEntry' object has no attribute 'endswith'
user10984358
am I doing something wrong?
@MisterMiyagi don't say that, piR2 might hear you
@TheNamesAlc yes
Look at os docs perhaps for some examples? Diagnose the problem?
user10984358
mind pointing that out?
user10984358
alright
@TheNamesAlc You're trying to look up an endswith method on a posix.DirEntry object.
user10984358
14:57
I will try to solve that on my own, might stay at top of my head for longer that way
perfect
user10984358
@AndrasDeak that much I know, I just replicated what @MisterMiyagi said but then again might be some small error or typo
We were talking about finding the endings of filenames. Minor detail that scandir doesn't give you strings.

« first day (3190 days earlier)      last day (1982 days later) »