locking

Many threads to write log file at same time in Python

人走茶凉 提交于 2019-12-18 04:48:16
问题 I am writing a script to retrieve WMI info from many computers at the same time then write this info in a text file: f = open("results.txt", 'w+') ## to clean the results file before the start def filesize(asset): f = open("results.txt", 'a+') c = wmi.WMI(asset) wql = 'SELECT FileSize,Name FROM CIM_DataFile where (Drive="D:" OR Drive="E:") and Caption like "%file%"' for item in c.query(wql): print >> f, item.Name.split("\\")[2].strip().upper(), str(item.FileSize) class myThread (threading

Implementing Optimistic Locking in Oracle

狂风中的少年 提交于 2019-12-18 04:24:14
问题 I am confused about the subject of locking in Oracle. As far as my research has lead me, you can use the FOR UPDATE NOWAIT/WAIT to lock rows. I want to implement my locking this way. Once I issue the FOR UPDATE , the row will then be locked and I can check for mutations. I have a versionNumber column that increments by 1 everytime the table is updated. Can i use this versionNumber to verify the row has or hasn't mutated? something like if (:new.versionNum != :old.versionNum) raise_application

Is this a valid pattern for raising events in C#?

我只是一个虾纸丫 提交于 2019-12-18 03:32:55
问题 Update : For the benefit of anyone reading this, since .NET 4, the lock is unnecessary due to changes in synchronization of auto-generated events, so I just use this now: public static void Raise<T>(this EventHandler<T> handler, object sender, T e) where T : EventArgs { if (handler != null) { handler(sender, e); } } And to raise it: SomeEvent.Raise(this, new FooEventArgs()); Having been reading one of Jon Skeet's articles on multithreading, I've tried to encapsulate the approach he advocates

Locking on an object?

笑着哭i 提交于 2019-12-18 03:15:22
问题 I'm very new to Node.js and I'm sure there's an easy answer to this, I just can't find it :( I'm using the filesystem to hold 'packages' (folders with a status extensions 'mypackage.idle') Users can perform actions on these which would cause the status to go to something like 'qa', or 'deploying' etc... If the server is accepting lots of requests and multiple requests come in for the same package how would I check the status and then perform an action, which would change the status,

Java blocking issue: Why would JVM block threads in many different classes/methods?

流过昼夜 提交于 2019-12-17 23:36:44
问题 Update: This looks like a memory issue. A 3.8 Gb Hprof file indicated that the JVM was dumping-its-heap when this "blocking" occurred. Our operations team saw that the site wasn't responding, took a stack trace, then shut down the instance. I believe they shut down the site before the heap dump finished. The log had no errors/exceptions/evidence of problems--probably because the JVM was killed before it could generate an error message. Original Question We had a recent situation where the

Why is “lock (typeof (MyType))” a problem?

感情迁移 提交于 2019-12-17 22:38:45
问题 MSDN gives the following warning about the lock keyword in C#: In general, avoid locking on a public type, or instances beyond your code's control. The common constructs lock (this), lock (typeof (MyType)), and lock ("myLock") violate this guideline: * lock (this) is a problem if the instance can be accessed publicly. * lock (typeof (MyType)) is a problem if MyType is publicly accessible. Yet it gives no solid reasoning for it. The lock(this) is explained here on SO. I'm interested in lock

accept() with sockets shared between multiple processes (based on Apache preforking)

 ̄綄美尐妖づ 提交于 2019-12-17 22:16:07
问题 I'm working on some Python code modeled on Apache's MPM prefork server. I am more an applications programmer than a network programmer and it's been 10 years since I read Stevens, so I'm trying to get up to speed in understanding the code. I found a short description of how Apache's prefork code works, by Sander Temme. The parent process, which typically runs as root, binds to a socket (usually port 80 or 443). It spawns children, which inherit the open file descriptor for the socket, and

yield returns within lock statement

一世执手 提交于 2019-12-17 19:37:19
问题 if i have a yield return in a lock statement does the lock get taken out on each yield (5 times in the example below) or only once for all the items in the list? Thanks private List<string> _data = new List<string>(){"1","2","3","4","5"}; private object _locker =new object(); public IEnumerable<string> GetData() { lock (_locker) { foreach (string s in _data) { yield return s; } } } 回答1: Edit: This answer was wrong, but I can't delete it as it was marked as correct. Please see @Lockszmith's

Mysql deadlock explanation needed

不想你离开。 提交于 2019-12-17 19:35:28
问题 I received the following deadlock log via "SHOW INNODB STATUS". Can someone care to explain why the transaction was aborted? It seems that Transaction 2 is holding the lock, but is also stuck requesting the same lock (except for the "waiting" part), which leads to a deadlock when Transaction 1 requires it as well. ===================================== 091205 6:25:01 INNODB MONITOR OUTPUT ===================================== Per second averages calculated from the last 39 seconds ----------

Lock vs. ToArray for thread safe foreach access of List collection

末鹿安然 提交于 2019-12-17 19:12:26
问题 I've got a List collection and I want to iterate over it in a multi threaded app. I need to protect it every time I iterate it since it could be changed and I don't want "collection was modified" exceptions when I do a foreach. What is the correct way to do this? Use lock every time I access or loop. I'm rather terrified of deadlocks. Maybe I'm just paranoid of using lock and shouldn't be. What do I need to know if I go this route to avoid deadlocks? Is lock fairly efficient? Use List<>