Skip to main content

Questions tagged [context-manager]

For code implementing a Python (or python-like) context manager, that can be scoped using the "with" statement.

2 votes
1 answer
65 views

Managing a global backend/device state when making a deep learning framework

I have been making a deep learning framework modelled after Pytorch in pure Python. I have made good progress but my framework is currently not seamless to use because the end user of the framework ...
Featherball's user avatar
8 votes
1 answer
290 views

CUDA/NVRTC context switching function

I've implemented a feature in my C++ fractal explorer application to switch between CUDA and NVRTC. The main reason for the NVRTC/Driver API context is to support runtime compilation of custom CUDA ...
NeKon's user avatar
  • 641
4 votes
6 answers
758 views

Generate all lines from a file matching a given word list

I have a script - generator that accepts a file name or file object and a list of search words as input. The generator searches through the lines of the file and returns only those lines (the whole ...
zaelcovsky's user avatar
2 votes
1 answer
113 views

Is using a generator of context managers kosher?

I know this is not necessarily a problem question but more of a style question. I understand that it doesn't have to be pretty for the most part. In general, context managers are used for mutexing, ...
georgwalker45's user avatar
2 votes
0 answers
108 views

Python context manager for importing modules outside my local directory

I implemented this context manager for importing modules from arbitrary directories. Good? Bad? - Keen to get thoughts: Implementation ...
MYK's user avatar
  • 141
1 vote
2 answers
889 views

More Pythonic Context Manager Wrapper

I wanted to ask this here because what I wanted to originally do felt like a really Pythonic method. I want to be able to use the syntax: ...
Stephen's user avatar
  • 125
5 votes
2 answers
2k views

Dictionary as context manager

I've created a class that implements customized addition, subtraction, etc. But for this class I'd like to have some additional parameters for these methods (__add__...
MSeifert's user avatar
  • 740
1 vote
1 answer
914 views

Context manager for SMTP connections

My code right now look like this ...
user1685095's user avatar
7 votes
1 answer
194 views

Switch like context manager in Python

This is self-explaining example with usage in doctests (it's not that fast as implementation with dict key-lookups, but it's a lot more readable, and don't require callables and lambdas): ...
canni's user avatar
  • 211