atomic

Is set.copy() atomic in Python?

Is set.copy() atomic in Python? Question: Suppose we have an instance variable in a class. class MyClass(object): def __init__(): self.set1 = set() Is the following operation atomic? set_shallow_copy = self.set1.copy() I’ve tried to search around, but the only information I’ve found is that reading instance variables are atomic. (Edit) I tried to decompile the bytecode …

Total answers: 2

python atomic data types

python atomic data types Question: It was written here that Python has both atomic and reference object types. Atomic objects are: int, long, complex. When assigning atomic object, it’s value is copied, when assigning reference object it’s reference is copied. My question is: why then, when i do the code bellow i get ‘True’? a …

Total answers: 4

Django – Rollback save with transaction atomic

Django – Rollback save with transaction atomic Question: I am trying to create a view where I save an object but I’d like to undo that save if some exception is raised. This is what I tried: class MyView(View): @transaction.atomic def post(self, request, *args, **kwargs): try: some_object = SomeModel(…) some_object.save() if something: raise exception.NotAcceptable() # …

Total answers: 3

Is a variable swap guaranteed to be atomic in python?

Is a variable swap guaranteed to be atomic in python? Question: With reference to the following link: http://docs.python.org/faq/library.html#what-kinds-of-global-value-mutation-are-thread-safe I wanted to know if the following: (x, y) = (y, x) will be guaranteed atomic in cPython. (x and y are both python variables) Asked By: dhruvbird || Source Answers: Yes, yes it will. I stand …

Total answers: 3

How to make file creation an atomic operation?

How to make file creation an atomic operation? Question: I am using Python to write chunks of text to files in a single operation: open(file, ‘w’).write(text) If the script is interrupted so a file write does not complete I want to have no file rather than a partially complete file. Can this be done? Asked …

Total answers: 7