locking

Python: Lock directory

浪子不回头ぞ 提交于 2019-12-01 21:53:01
问题 AFAIK this code can be used to lock a directory: class LockDirectory(object): def __init__(self, directory): assert os.path.exists(directory) self.directory = directory def __enter__(self): self.dir_fd = os.open(self.directory, os.O_RDONLY) try: fcntl.flock(self.dir_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) except IOError as ex: if ex.errno != errno.EAGAIN: raise raise Exception('Somebody else is locking %r - quitting.' % self.directory) def __exit__(self, exc_type, exc_val, exc_tb): self.dir_fd

Locking and unlocking files using the java API

ⅰ亾dé卋堺 提交于 2019-12-01 21:33:34
问题 One of our clients is using some Novel security software that sometimes locks some .class files that our software creates. This causes some nasty problems for them when this occurs and I am trying to research a workaround that we could add to our error handling to address this problem when it comes up. I am wondering are there any calls in the java api that can be used to detect if a file is locked, and if it is, unlock it. 回答1: Before attempting to write to a file, you can check if the file

Locking Files in Bash

陌路散爱 提交于 2019-12-01 21:17:42
I have a Problem to find a good concept on locking files in bash, Basically I want to achieve the following: Lock File Read in the data in the file (multiple times) Do stuff with the data. Write new stuff to the file (not necessarily to the end) Unlock that file Doing this with flock seems not possible to me, because the file descriptor will just move once to the end of the file. Also creating a Tempfile fails, because I might overwrite already read lines which is also not possible. Edit: Also note that other scripts I do not control might try to write to that file. So my question is how can I

Is there any reason to lock on something other than new object()?

混江龙づ霸主 提交于 2019-12-01 20:13:29
问题 object theLock = new object(); ... lock (theLock) { ... } I always use a new object() for this, but I'm wondering: are there any circumstances in which you would lock on a more specific type? 回答1: In case of a new , the Type doesn't matter, the instance do. In this case you're talking about a synclock object : an object which is used to lock code(s) section(s) to prevent concurrent access. Using another Type than object for a synclock is a waste of memory because you don't use this instance

atomically creating a file lock in MATLAB (file mutex)

▼魔方 西西 提交于 2019-12-01 20:10:10
问题 I am looking for a simple already implemented solution for atomically creating a file lock in MATLAB. Something like: file_lock('create', 'mylockfile'); %this will block until it creates the lock file. file_lock('remove', 'mylockfile'); %this will remove the lock file: This question has already been asked several times, with some proposed solution ideas (such as using Java FileLock ), but I didn't find a simple already implemented solution. Are you aware of such an implemented solution? Notes

Locking and unlocking files using the java API

谁都会走 提交于 2019-12-01 20:00:20
One of our clients is using some Novel security software that sometimes locks some .class files that our software creates. This causes some nasty problems for them when this occurs and I am trying to research a workaround that we could add to our error handling to address this problem when it comes up. I am wondering are there any calls in the java api that can be used to detect if a file is locked, and if it is, unlock it. Before attempting to write to a file, you can check if the file is writable by your java application using File.canWrite() . However, you still might run into an issue if

How to disable the lock system of JPA?

谁说我不能喝 提交于 2019-12-01 19:37:26
I'm using OpenJPA and I have a lock problem. I already understand what's an OptimisticLockException and when it's thrown. But how can I deal with it ? Below*, you can find a small paragraph about the optimistic lock exceptions. In a nutshell, how I can totally disable the lock manager ? In my persistent.xml, I have the following xml code but it does not work. Why ? ... <properties> <property name="openjpa.LockManager" value="none" /> </properties> ... *According to the wikibooks about the Java Persistent : Handling optimistic lock exceptions Unfortunately programmers can frequently be too

Neo4j: Unable to lock store

心不动则不痛 提交于 2019-12-01 19:36:00
I'm using Neo4j graph DB and viewing the data on the browser. So whenever I run a code, i need to change database location field in neo4j-server.properties file. When i try to access DB with browser on I'm getting the following error: Exception in thread "main" java.lang.IllegalStateException: Unable to lock store [<DB path>], this is usually a result of some other Neo4j kernel running using the same store. Is it possible to view the database without locking the store? There is another process using the db. For instance, you opened it with another program (e.g. a gremlin shell in a terminal)

Are basic arithmetic operations in C# atomic

我是研究僧i 提交于 2019-12-01 19:34:37
Are the basic arithmetic operations Thread safe? For example, if there is ++ operation on a global variable, which will be modified from different threads, is it necessary to a lock around it? For example void MyThread() // can have many running instances { aGlobal++; } or should it be void MyThread() { lock( lockerObj) { aGlobal++; } } The spec sums it up very well. Section 5.5, "Atomicity of variable references": Reads and writes of the following data types are atomic: bool, char, byte, sbyte, short, ushort, uint, int, float, and reference types. In addition, reads and writes of enum types

using java FileChannel FileLock to prevent file writes but allow reads

牧云@^-^@ 提交于 2019-12-01 19:24:15
问题 I think I'm misunderstanding how the FileChannel's locking features work. I want to have an exclusive write lock on a file, but allow reads from any process. On a Windows 7 machine running Java 7, I can get FileChannel's lock to work, but it prevents both reads and writes from other processes. How can I achieve a file lock that disallows writes but allows reads by other processes? 回答1: FileChannel.lock() deals with file regions, not with the file itself. The lock can be either shared (many