642 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
1
vote
1
answer
103
views
Order of execution in FastAPI async generators
This is the code
@router.post("/tel/verify-otp",
summary="Verify OTP and update user tel number"
)
async def verify_tel_otp(
command: ...
0
votes
1
answer
118
views
Actual practical advantage of SQLAlchemy scoped_session vs classic session in worker
What is the actual practical advantage of using a scoped_session vs a normal session when using a contextmanager to handle opening and closing of the session at the appropriate times?
In the following ...
1
vote
1
answer
104
views
Is with concurrent.futures.Executor blocking?
Why
when using separate with, the 2nd executor is blocked until all tasks from 1st executor is done
when using a single compound with, the 2nd executor can proceed while the 1st executor is still ...
0
votes
0
answers
88
views
To create multiple cursors with one connection object using context manager in Python for Snowflake
I'm really looking for best practices here, or something I've not thought of.
I have scripts which loop through multiple tables (potentially hundreds) in Snowflake within Snowflake, and do some form ...
0
votes
1
answer
88
views
How to temporarily change a class object?
Considering the following class and object:
class foo:
def __init__(self,name):
self.name = name
def print_name(self):
print(self.name)
object1 = foo('...
2
votes
1
answer
274
views
Context managers as attributes
I am having a hard time to write clean code with context managers in Python without getting in a context manager hell. Imagine something like:
class A:
def __init__(self):
self.b = B() # ...
1
vote
1
answer
74
views
Python context manager that backs up and restores `cwd` leaves terminal in erroneous state
I have a context manager that temporarily backs up a directory and restores it upon exit. Here's the implementation:
import shutil
import tempfile
from pathlib import Path
from contextlib import ...
1
vote
2
answers
670
views
How to extend the lifespan of an object under asynccontextmanager into a background task in FastAPI?
I use an object that needs a startup and a teardown process (load from/save to cache, for example) in a FastAPI endpoints. I used a asynccontextmanager to manage the context of an object, but I also ...
1
vote
1
answer
139
views
How can I mock multiple context managers and function calls with pytest in async contexts?
I'm writing tests for a python fastApi applciation, however, the issue is not directly related to fastAPI itself. I have a block of code that doesn't seem to be mocked properly, and the offending code ...
0
votes
1
answer
837
views
How to make dynamic widgets in DearPyGUI?
It is well possible to experiment with the problem of a dynamic widget on tables:
import dearpygui.dearpygui as dpg
from typing_extensions import Union, Optional, Any
# * Local Imports
import database
...
3
votes
3
answers
236
views
Dealing with interlacing lock in Python3
I am trying to implement the following logic in Python3:
# Clarification:
# function f() is the only function that would acquire both locks
# It is protected by other locks so f() itself has no ...
0
votes
0
answers
87
views
How do I use an asyncio context manager with Jupyter notebooks to create new tasks?
I have a class called Series, which inherits from a base class called Fred. Series has a number of methods, which retrieve data from different API end points and process that data into properties of ...
0
votes
1
answer
64
views
Mocked database cursor context manager missing the '__enter__'
I have created a database fixture
@pytest.fixture
def mock_db(mocker):
"""Fixture for setting up a mock database connection."""
mock_cursor = mocker.MagicMock()
...
0
votes
1
answer
102
views
Capture KeyboardInterrupt in context manager when OpenMPI run is manually terminated
I am running code in parallel using mpi4py. I've noticed that if I run the code and perform a keyboard interrupt, my context manager __exit__ will run if I run the code as python file.py but will not ...
-2
votes
1
answer
154
views
Is it possible to implement RAII with Python in the context of ensuring that the close() function is called on opened files?
I asked a question earlier today, Is it important to call close() on an file opened with open() if flush() is called after each write() operation?
I asked this question while thinking about data loss, ...