コード例 #1
0
ファイル: darwin.py プロジェクト: AJMartel/3DPrinter
 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
コード例 #2
0
    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'))
コード例 #3
0
ファイル: EkoAppDelegate.py プロジェクト: bytearchive/eko
 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)
コード例 #4
0
    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"))
コード例 #5
0
 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
コード例 #6
0
ファイル: _singleton.py プロジェクト: eaganj/jre
 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
コード例 #7
0
ファイル: EkoAppDelegate.py プロジェクト: bytearchive/eko
 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()
コード例 #8
0
ファイル: EkoAppDelegate.py プロジェクト: lericson/eko
 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()
コード例 #9
0
    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
コード例 #10
0
    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
コード例 #11
0
ファイル: test_locking.py プロジェクト: ronaldoussoren/pyobjc
    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"))
コード例 #12
0
ファイル: test_locking.py プロジェクト: Joey-Lee/pyobjc
    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'))
コード例 #13
0
ファイル: _singleton.py プロジェクト: eaganj/jre
 def allocWithZone_(cls, zone):
     with objc.object_lock(cls):
         if cls._sharedSingleton is None:
             return super(JRESingleton, cls).allocWithZone_(zone)
     
     return None
コード例 #14
0
ファイル: EkoAppDelegate.py プロジェクト: lericson/eko
 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)