filelock

Lock file when writing to it from parallel processes in R

瘦欲@ 提交于 2019-12-19 06:16:12
问题 I use parSapply() from parallel package in R. I need to perform calculations on huge amount of data. Even in parallel it takes hours to execute, so I decided to regularly write results to a file from clusters using write.table() , because the process crashes from time to time when running out of memory or for some other random reason and I want to continue calculations from the place it stopped. I noticed that some lines of csv files that I get are just cut in the middle, probably as a result

Unable to lock files on Linux using java.nio.channels.FileLock

时光总嘲笑我的痴心妄想 提交于 2019-12-17 22:28:26
问题 I was creating an application in Java for which I want only one instance running. For this purpose I created a file and got a lock while my application is running. I have following code which works on Windows, but failed on Linux: once I acquire a lock without unlocking it I can get another lock on it. import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; public class MyApp { private static

FileStream with locked file

我的未来我决定 提交于 2019-12-17 21:05:15
问题 I am wondering if it's possible to get a readonly FileStream to a locked file? I now get an exception when I try to read the locked file. using (FileStream stream = new FileStream("path", FileMode.Open)) Thanks! 回答1: You should try another constructor. They are documented at MSDN. This one looks like a bet: FileStream Constructor (String, FileMode, FileAccess, FileShare) MSDN Link FileAccess A constant that determines how the file can be accessed by the FileStream object. This gets the

How to check in command-line if a given file or directory is locked (used by any process)?

安稳与你 提交于 2019-12-17 02:24:16
问题 I need to know that before any attempt to do anything with such file. 回答1: Not sure about locked directories (does Windows have that?) But detecting if a file is being written to by another process is not difficult. @echo off 2>nul ( >>test.txt echo off ) && (echo file is not locked) || (echo file is locked) I use the following test script from another window to place a lock on the file. ( >&2 pause ) >> test.txt When I run the 2nd script from one window and then run the 1st script from a

Move a file without releasing lock

℡╲_俬逩灬. 提交于 2019-12-12 17:14:05
问题 I am using Java NIO in spring batch application. The application looks in a directory (e.g. /shared/inbox) where /shared is network shared disk among all instances of applications running on different JVMs. To avoid multiple threads reading same files, in my ItemReader I take a FileLock and avoid other threads to read from it. While I am done reading, I want to move the file to another directory (e.g. /shared/archive). But the Files.move method cannot do that unless I give up the FileLocl,

Unable to read from newly locked file

有些话、适合烂在心里 提交于 2019-12-11 17:53:08
问题 So I try to locked the file to read it, but I got IOException, any idea why? public static void main(String[] args){ File file = new File("C:\\dev\\harry\\data.txt"); FileReader fileReader = null; BufferedReader bufferedReader = null; FileChannel channel = null; FileLock lock = null; try{ channel = new RandomAccessFile(file, "rw").getChannel(); lock = channel.lock(); fileReader = new FileReader(file); bufferedReader = new BufferedReader(fileReader); String data; while((data = bufferedReader

Close a file handle opened by .NET

一个人想着一个人 提交于 2019-12-11 09:53:49
问题 I'm working on a script to rename files based on EXIF data. param([string]$path) # http://blogs.technet.com/b/jamesone/archive/2007/07/13/exploring-photographic-exif-data-using-powershell-of-course.aspx [reflection.assembly]::loadfile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll") | out-null function MakeString { $s="" for ($i=0 ; $i -le $args[0].value.length; $i ++) { $s = $s + [char]$args[0].value[$i] } return $s } $files = Get-ChildItem -Path $path foreach ($file in

Ruby: How to acquire file lock for writing?

泄露秘密 提交于 2019-12-11 07:40:22
问题 What I want to achieve is this: if some other process is holding the lock, quit otherwise acquire the lock for writing The Ruby code I am trying to modify is. File.open(filename, "wb") { |inf| if inf.flock(File::LOCK_EX|File::LOCK_NB) == 0 ... end } The codes I can find are usually using "rb" . If I change to "wb" , there is a problem: because if some other process is working on the file (which I cannot know until attempting the lock), the file will be wiped out by File.open(..., "wb") . Is

Cannot delete an image file that is shown in a listview

ぐ巨炮叔叔 提交于 2019-12-10 17:27:58
问题 In my listview I show thumbnails of small images in a certain folder. I setup the listview as follows: var imageList = new ImageList(); foreach (var fileInfo in dir.GetFiles()) { try { var image = Image.FromFile(fileInfo.FullName); imageList.Images.Add(image); } catch { Console.WriteLine("error"); } } listView.View = View.LargeIcon; imageList.ImageSize = new Size(64, 64); listView.LargeImageList = imageList; for (int j = 0; j < imageList.Images.Count; j++) { var item = new ListViewItem

Java file locking and Windows - the lock isn't “absolute”?

爱⌒轻易说出口 提交于 2019-12-08 21:47:48
问题 I'm trying to lock a file with Java in Windows environment with FileLock and I got an issue : after I lock the file it can still be accessed by other processes at least on some level. Example code follows: public class SimpleLockExample { public static void main(String[] args) throws Exception { String filename = "loremlipsum.txt"; File file = new File(filename); RandomAccessFile raf = new RandomAccessFile(file, "rw"); FileChannel channel = raf.getChannel(); FileLock lock = null; try { lock =