def init(self): self = super(PowerSourcesNotificationsObserver, self).init() if self is not None: self._weak_observers = [] self._thread = None self._lock = objc.object_lock(self) return self
def testObjectiveCLocking(self): lst = [] lst = [] obj = BaseClass.alloc().initWithList_(lst) lck = objc.object_lock(obj) thr = ObjCThread(obj) thr.start() for i in range(5): time.sleep(0.1) lck.lock() self.assertFalse(obj.isLocked()) obj.setLocked_(True) obj.appendToList_("mainthread") time.sleep(0.5) obj.setLocked_(False) lck.unlock() thr.join() self.assertNotIn("LOCK FOUND", lst) for idx in range(len(lst)): if lst[idx].endswith(' a'): self.assertTrue(lst[idx + 1].endswith(' b'))
def emit_request_forwarded(self, request, response): req_item = RequestItem.from_emission(request, response) with object_lock(self.request_items): self.request_items.append(req_item) NSApp.delegate( ).requestView.performSelectorOnMainThread_withObject_waitUntilDone_( "reloadData", None, False)
def testObjectiveCLocking(self): lst = [] lst = [] obj = BaseClass.alloc().initWithList_(lst) lck = objc.object_lock(obj) thr = ObjCThread(obj) thr.start() for i in range(5): time.sleep(0.1) lck.lock() self.assertFalse(obj.isLocked()) obj.setLocked_(True) obj.appendToList_("mainthread") time.sleep(0.5) obj.setLocked_(False) lck.unlock() thr.join() self.assertNotIn("LOCK FOUND", lst) for idx in range(len(lst)): if lst[idx].endswith(" a"): self.assertTrue(lst[idx + 1].endswith(" b"))
def init(self): self = super(JRESingleton, self).init() if not self: return self with objc.object_lock(self.__class__): if self.__class__._sharedSingleton is None: self.__class__._sharedSingleton = self return self.__class__._sharedSingleton
def updateURLs_(self, sender): target_url = self.targetURL.stringValue() namespace = self.namespace.stringValue() with object_lock(self.request_items): self.request_items[:] = [] self.requestView.reloadData() if hasattr(self, "client_thread"): self.client_thread.cancel() self.client_thread = EkoClientThread.newAtURL_usingNamespace_withItems_( target_url, namespace, self.request_items) self.client_thread.start()
def run(self): pool = NSAutoreleasePool.alloc().init() lck = objc.object_lock(self.obj) for i in range(6): time.sleep(0.05) lck.lock() if self.obj.isLocked(): self.obj.appendToList_("LOCK FOUND") self.obj.setLocked_(True) self.obj.appendToList_("thread %d a" % (i, )) time.sleep(0.5) self.obj.appendToList_("thread %d b" % (i, )) self.obj.setLocked_(False) lck.unlock() del pool
def run(self): pool = NSAutoreleasePool.alloc().init() lck = objc.object_lock(self.obj) for i in range(6): time.sleep(0.05) lck.lock() if self.obj.isLocked(): self.obj.appendToList_("LOCK FOUND") self.obj.setLocked_(True) self.obj.appendToList_("thread %d a" % (i,)) time.sleep(0.5) self.obj.appendToList_("thread %d b" % (i,)) self.obj.setLocked_(False) lck.unlock() del pool
def testBasicLocking(self): lst = [] lst = [] obj = BaseClass.alloc().initWithList_(lst) thr = OtherThread(obj) thr.start() for _ in range(5): time.sleep(0.1) with objc.object_lock(obj): self.assertFalse(obj.isLocked()) obj.setLocked_(True) obj.appendToList_("mainthread") time.sleep(0.5) obj.setLocked_(False) thr.join() self.assertNotIn("LOCK FOUND", lst) for idx in range(len(lst)): if lst[idx].endswith(" a"): self.assertTrue(lst[idx + 1].endswith(" b"))
def testBasicLocking(self): lst = [] obj = BaseClass.alloc().initWithList_(lst) lck = objc.object_lock(obj) thr = OtherThread(obj) thr.start() for i in range(5): time.sleep(0.1) lck.lock() self.assert_(not obj.isLocked()) obj.setLocked_(True) obj.appendToList_("mainthread") obj.setLocked_(False) lck.unlock() thr.join() self.assert_("LOCK FOUND" not in lst) for idx in range(len(lst)): if lst[idx].endswith(' a'): self.assert_(lst[idx+1].endswith(' b'))
def allocWithZone_(cls, zone): with objc.object_lock(cls): if cls._sharedSingleton is None: return super(JRESingleton, cls).allocWithZone_(zone) return None
def emit_request_forwarded(self, request, response): req_item = RequestItem.from_emission(request, response) with object_lock(self.request_items): self.request_items.append(req_item) NSApp.delegate().requestView.performSelectorOnMainThread_withObject_waitUntilDone_( "reloadData", None, False)