示例#1
0
 def baker(self):
     for i in range(10):
         with self.__lock:
             l.info(f"Storage : {self.storage}")
             threading.sleep(0.1)
             self.storage += 1
             threading.sleep(1)
示例#2
0
文件: base.py 项目: lilnana00/3ddd
    def _do_post(self, url, params, headers=None):

        response = self._requests_post(url,
                                       headers=headers,
                                       params=params,
                                       timeout=self.configuration.timeout)
        if response.status_code != 408:
            return response, 0

        count = 1
        while count < len(self.configuration.retries):
            YLogger.warning(
                self, "Timeout, sleeping for {0}ms".format(
                    (self.configuration.retries[count])))
            threading.sleep(self.configuration.retries[count])

            response = self._requests_post(url,
                                           headers=headers,
                                           data=params,
                                           timeout=self.configuration.timeout)
            if response.status_code != 408:
                break

            count += 1

        return response.count
示例#3
0
def grab_post(p, postDict, session, success, user_dir):
    try:
        pid = getPostID(p)

        if pid == None:
            m = hashlib.md5()
            m.update(str(p))
            pid = "__md5" + m.hexdigest()

        tags = tagsInPost(p)

        if not postDict.has_key(pid):
            postDict[pid] = {}
            postDict[pid]["tags"] = []
            postDict[pid]["images"] = []
            postDict[pid]["text"] = ""

        postDict[pid]["tags"] = set(postDict[pid]["tags"])
        for t in tags:
            if isinstance(t, Tag):
                tagString = t.getText().replace("#", "")
                postDict[pid]["tags"].add(tagString)

        images = imagesInPost(p)
        longImagePaths = download_images(user_dir, images, session)
        postDict[pid]["images"] = map(os.path.basename, longImagePaths)
        postDict[pid]["tags"] = list(postDict[pid]["tags"])
        postDict[pid]["text"] = str(p)
        success = True
    except SocketError:
        success = False
        threading.sleep(10);
    return success
示例#4
0
 def customer(self):
     for i in range(10):
         with self.__lock:
             l.info(f"Storage : {self.storage}")
             threading.sleep(0.2)
             if self.storage >= 2:
                 self.storage -= 2
             threading.sleep(1)
示例#5
0
    def start(self):
        '''单人战斗主循环'''
        while self.run:
            self.log.writeinfo(self.name + '开始寻找是否有车')
            # 等待一个小时
            self.yys.wait_game_img(r'img/MIJING.png', 60 * 60)

            position = self.yys.wait_game_img(r'img/JIN-RU.png', 10)
            self.log.writeinfo(self.name + '找到车了')
            self.yys.mouse_click_bg(position)
            threading.sleep(random.randint(100, 200))
    def GoNextPage(self):
        paging = self.paging.GetElement(self.driver)
        num = paging.find_element_by_class_name("num")
        current_page = num.find_element_by_class_name("on").text

        pages = num.find_elements_by_tag_name("a")
        for page in pages:
            if page.text == str(int(current_page) + 1):
                print("Go to the next page: ", str(int(current_page) + 1))
                page.send_keys(Keys.ENTER)
                while True:
                    paging = self.paging.GetElement(self.driver)
                    num = paging.find_element_by_class_name("num")
                    current_page1 = num.find_element_by_class_name("on").text
                    if current_page1 == str(int(current_page) + 1):
                        break
                    threading.sleep(5)
                return True
        
        btns = paging.find_elements_by_class_name("btn")
        for btn in btns:
            href = btn.find_element_by_tag_name("a").get_attribute("href")
            page = href.split("#")[-1]
            if page == str(int(current_page) + 1):
                print("Go to the next page: ", str(int(current_page) + 1))
                btn.find_element_by_tag_name("a").send_keys(Keys.ENTER)
                while True:
                    paging = self.paging.GetElement(self.driver)
                    num = paging.find_element_by_class_name("num")
                    current_page1 = num.find_element_by_class_name("on").text
                    if current_page1 == str(int(current_page) + 1):
                        break
                    threading.sleep(5)
                return True

        return False
示例#7
0
remote_address = '127.0.0.1'

remote_address = sys.argv[1]

connect_port = int(sys.argv[2])

mode = sys.argv[3]



socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.bind(local_address)
socket.connect((remote_address,connect_port))
if mode == 'read':
    while True:
        try:
            data = socket.recv(1024)
            print 'recv data ', data
        except Exception:
            pass
else:
    while True:
        try:
            data = str(random.randint(0,10))
            socket.sendall(data)
            threading.sleep(3)
        except Exception:
            pass

示例#8
0
文件: core.py 项目: jwg4/PyAsync
def sleep(time):
    """block for a certain amount of time"""
    threading.sleep(time)
    return determined(None)
示例#9
0
 def get_dns_response(self, query):
     threading.sleep(2)
     return b'Placeholder'