« first day (4544 days earlier)      last day (387 days later) » 

2:35 AM
duplicate (I noticed too late because I was explaining how to MRE) stackoverflow.com/questions/75845366
 
 
14 hours later…
5:05 PM
I don't have anything even close to an MRE, but I sometimes get this weird asyncio error:
an error occurred during closing of asynchronous generator <async_generator object PartFileDestination.open_file at 0x000001A86DF106D0>
asyncgen: <async_generator object PartFileDestination.open_file at 0x000001A86DF106D0>
RuntimeError: aclose(): asynchronous generator is already running
Does anyone have an idea what could be causing it? I'm completely stumped here
For context, PartFileDestination.open_file is a @contextlib.asynccontextmanager. Essentially:
class PartFileDestination(FilePathDestination):
    @contextlib.asynccontextmanager
    async def open_file(self, download):
        async with aiofiles.open('download.part', 'wb') as file:
            yield file
 
@Aran-Fey Might be relevant for you: bpo#38559
Basically if your async generator is await-paused while doing cleanup, nasal daemons may spawn.
 
Wait, what? You're saying I mustn't await anything after the yield?
... or wrap the yield in an async with, for that matter?
If I understand correctly, something is causing two methods of my context manager to be executed at the same time - could be __aenter__ and __aexit__, or could be __aexit__ and __aexit__. Or am I not on the right track there?
Considering that I never manually call those methods, I can't imagine how that would happen. I only use async with, which translates to exactly 1 __aenter__ and 1 __aexit__
 
6:21 PM
This is my code
 
@pythonhater Please review the room rules for posting code fragments - up to about 8 or 10 lines is the limit, after that paste your code to a pastebin like dpaste and just post the link
Room rules are in the header, and I repost here for your convenience: sopython.com/chatroom
Also, it would be best if you added a few comments about why you want us to look at this code.
 
I am trying to do a hyperparameter tuning. I used pytorch. I want to print the results in a txt file. In the evaluation results on the training set in the last part of my code. I want to print Hit ratio, nDCG, MRR. however i do not know how can i write a function for them to include them here. can you help me?
Cabbage
 
I'm not really a PyTorch expert. Did you post this as a general question to SO? There are probably more PyTorch experts there than here.
 
6:45 PM
print('\n')
print('Evaluation results on the training set:')
# age group fairness
group_fairness_age = group_fairness(S_train[:,0],Variable((torch.from_numpy(data_X_train)).float()),best_net)
print(f"Group fairness for age: {group_fairness_age: .4f}")
# gender group fairness
group_fairness_gender = group_fairness(S_train[:,1],Variable((torch.from_numpy(data_X_train)).float()),best_net)
print(f"Group fairness for gender: {group_fairness_gender: .4f}")
# race group fairness
group_fairness_race = group_fairness(S_train[:,2],Variable((torch.from_numpy(data_X_train)).float()),best_net)
# HR, NDCG, MRR printing in the result section. I do not know how to write a function for them to calculate based on my code.
 
@Aran-Fey No, it's a general problem of async generators. If the generator awaits during __anext__*and* someone tries to close it (say, asyncio), async gazes back into you.
It should be fine in newer versions of Python, provided you use asyncio.run.
 
7:02 PM
No asyncio.run here, unfortunately. And I don't understand how python would end up running two methods of my context manager at the same time. If an exception occurs during __aenter__, surely __aenter__ will stop running before @asynccontextmanager calls __aexit__?
Actually... There isn't even a try: in that function. If an exception occurs, nothing more should be executed at all
Plus, doesn't the "an error occurred during closing of asynchronous generator" message imply that this is happening during loop.shutdown_asyncgens()? All context managers should be closed at that point
Nothing makes sense in async land
 
7:20 PM
@Aran-Fey No, only if the tasks have been cancelled. asyncio.run does that correctly, but many tutorials showing the various loop.run_… methods don't.
 
Hmm. I'm cancelling all of my downloads, but I guess I'll add a for task in asyncio.all_tasks(loop): task.cancel() and see if it makes a difference
 
8:23 PM
Is there any way to annotate "at least one of the arguments is of a given type"?
Something like def f(*args_before: A | B, arg: B, *args_after: A | B).
I want to @overload a special case where at least one of the arguments is of type B.
 
That's not possible, no. Best you can do is hard-code some of the variations as @overloads
 
8:49 PM
There are infinite possible variations, unfortunately, since the number of arguments is unlimited. It would also take an exponential number of hard-codings even if the maximum number of arguments were finite.
I posted the question here anyway in case someone finds a solution.
0
Q: Type annotation for &quot;at least one argument is of type X&quot;

user76284I'm trying to use overloading to make the return type of a variadic function depend on the type of its arguments in a certain way. Specifically, I want the return type to be X if and only if any of its arguments is of type X. Consider the following minimal example: from typing import overload, Na...

 
Makes me wonder why I bothered to answer the question
 
9:16 PM
Ok I'm dumb, that is possible
...if you ditch mypy and adopt pyright
 

« first day (4544 days earlier)      last day (387 days later) »