def Reset(self): self.StopTcpServer() self.StartTcpServer() self.SendVideo = Thread(target=self.sendvideo) self.ReadData = Thread(target=self.readdata) self.SendVideo.start() self.ReadData.start()
def pms_fwk_modifydict_wrapper(f): lockname = "Framework.ModDict:" + key Thread.Lock(lockname, addToLog=False) dictitem = Dict.Get(key) f(dictitem) Dict.Set(key, dictitem, addToLog=False) Thread.Unlock(lockname, addToLog=False)
def Log(msg, debugOnly=True, encoding=None): if not debugOnly or Plugin.Debug: global __logSaveScheduled global __logSaveBuffer # Try to decode the message if the encoding is specified try: if encoding is not None: msg = str(msg.decode(encoding).encode("utf8")) except: pass msg = "%s: %-40s: %s" % (str( Datetime.Now().time()), Plugin.Identifier, msg) # Don't write to stderr on Windows, it causes issues. if __sys.platform != "win32": __sys.stderr.write("%s\n" % msg) Thread.Lock("Framework.Log", addToLog=False) if __logSaveBuffer == None: __logSaveBuffer = msg + "\n" else: __logSaveBuffer += msg + "\n" if not __logSaveScheduled: Thread.CreateTimer(5, __saveLog) __logSaveScheduled = True Thread.Unlock("Framework.Log", addToLog=False)
def lock(f): lockname = "Framework.Lock:" + f.__name__ try: Thread.Lock(lockname, addToLog=False) f() finally: Thread.Unlock(lockname, addToLog=False) return f
def Set(key, value, addToLog=True): global __dict global __saveScheduled Thread.Lock("Framework.Dict", addToLog=False) __dict[key] = value if not __saveScheduled: Thread.CreateTimer(5, __save, addToLog=addToLog) __saveScheduled = True Thread.Unlock("Framework.Dict", addToLog=False)
def timer(self): i = 19 while self._flag: print ("\t\t\t%s \r" % (i * "=")) sys.stdout.flush() i = (i + 1) % 20 time.sleep(0.05) print ("\t\t\t%s\n" % (19 * "=")) Thread.exit_thread()
def __saveLog(): global __logSaveBuffer global __logSaveScheduled Thread.Lock("Framework.Log", False) f = open(Plugin.__logFilePath, 'a') f.write("%s\n" % __logSaveBuffer) f.close() __logSaveBuffer = None __logSaveScheduled = False Thread.Unlock("Framework.Log", addToLog=False)
def __save(addToLog=True): Thread.Lock("Framework.Dict", addToLog=False) dictToSave = copy.deepcopy(__dict) global __saveScheduled __saveScheduled = False try: Data.__pickle("%s/Dict" % Data.__dataPath, dictToSave) if addToLog: PMS.Log("(Framework) Saved the dictionary file") finally: Thread.Unlock("Framework.Dict", addToLog=False)
def __startCacheManager(firstRun=False): Thread.CreateTimer(HTTP.__autoUpdateCacheTime, __triggerAutoHTTPCacheUpdate) if "UpdateCache" in __pluginModule.__dict__: if firstRun: Thread.Create(__triggerCacheUpdate) else: Thread.CreateTimer((__cacheUpdateInterval / 2) + random.randrange(__cacheUpdateInterval), __triggerCacheUpdate) PMS.Log("(Framework) Cache manager started")
def __runtask__(self, t): lockname = "Framework.Parallel." + self.tasksetname taskset = parallel.tasksets[self.tasksetname] Thread.Lock(lockname, addToLog=False) self.threadcount += 1 Thread.Unlock(lockname, addToLog=False) try: t() finally: Thread.Lock(lockname, addToLog=False) self.threadcount -= 1 Thread.Unlock(lockname, addToLog=False)
def __call__(self, f): self.name = f.__name__ if progressive_load.loaders.has_key(self.name): self = progressive_load.loaders[self.name] else: PMS.Log("(Framework) Started a new progressive loader named '%s'" % self.name) self.__function = f self.last_fetch_time = Datetime.Now() progressive_load.loaders[self.name] = self Thread.Create(progressive_load.__runLoader, self) i = 0 while i < 10 and len(self.container) == 0: Thread.Sleep(0.1) return self.getContainer()
def __save(): global __saveScheduled Thread.Lock("Framework.HTTPCache", addToLog=False) try: # Save the cache Data.__pickle("%s/HTTPCache" % Data.__dataPath, __cache) # Save the cookie jar if __cookieJar is not None: __cookieJar.save("%s/HTTPCookies" % Data.__dataPath) finally: __saveScheduled = False Thread.Unlock("Framework.HTTPCache", addToLog=False) PMS.Log("(Framework) Saved shared HTTP data")
def __save(): global __prefs global __prefsPath Thread.Lock("Framework.Prefs", addToLog=False) try: userPrefs = XML.Element("PluginPreferences") for pref in __prefs: if pref.has_key("value"): userPrefs.append(XML.Element(pref["id"], pref["value"])) f = open(__prefsPath, "w") f.write(XML.StringFromElement(userPrefs)) f.close() PMS.Log("(Framework) Saved the user preferences file") finally: Thread.Unlock("Framework.Prefs", addToLog=False)
def part2(instructions): """ Get the amount of times thread1 send a value by the time we reach a deadlock """ thread0 = Thread(0) thread1 = Thread(1) while True: val1 = thread0.run(instructions) if val1 and val1 != 'wait': thread1.add_queue(val1) val2 = thread1.run(instructions) if val2 and val2 != 'wait': thread0.add_queue(val2) if val1 == val2 == 'wait': return len(thread1.send)
def __triggerCacheUpdate(): global UpdatingCache if UpdatingCache: return UpdatingCache = True __callNamed("UpdateCache", addToLog=False) Thread.CreateTimer(__cacheUpdateInterval, __triggerCacheUpdate) UpdatingCache = False
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.__map = dict() self.__rootLayout = QtWidgets.QVBoxLayout(self) self.__form = QtWidgets.QFormLayout(self) self.__vectorBase = { "One-Click": [[[win32con.MOD_SHIFT], 49], 'Shift+1'], "Create Note": [[[win32con.MOD_CONTROL], 50], 'Ctrl+2'], "Paste Back": [[[win32con.MOD_CONTROL, win32con.MOD_SHIFT], 51], 'Ctrl+Shift+3'], "Save File": [[[win32con.MOD_ALT], 52], 'Alt+4'] } self.__btn = QtWidgets.QPushButton(self) self.__btn.setText("Add Element") view = Windows.HotKeyObjectView("Enter name here") self.__btn.clicked.connect(lambda: self.onAddButton(view)) for category in self.__vectorBase: self.onOkAddButton( Windows.HotKeyObjectView(category, self.__vectorBase[category][0], self.__vectorBase[category][1])) self.__keyThread = Thread.HotKeyThread(self.__map) self.__keyThread.showMessage.connect(self.messageShow) self.__keyThread.start() self.__rootLayout.addLayout(self.__form) self.__rootLayout.addWidget(self.__btn) self.setLayout(self.__rootLayout)
def __loadDB(): global __dbThread __dbThread = Thread.Create(__loadDBInThread) # Give the database thread time to start accepting queries while not __alive: time.sleep(0.1) # If the database needs to be created, load the defaults file & call the create function if __shouldCreate: try: path = "%s/Contents/DefaultDatabase.sql" % Plugin.__bundlePath if os.path.exists(path): f = open(path, "r") string = f.read() f.close() Exec(string) PMS.Log("(Framework) Loaded the default database file") Commit() Plugin.__callNamed("CreateDatabase") PMS.Log("(Framework) Created database tables") except: PMS.Log("(Framework) Error creating database tables", False) finally: Commit()
def word_frequency_detection(word_to_detect): TOTAL_WORD_COUNT = 0 #Count the number of appreance in the text voice_data_queue = Queue() #Acquire voice clip for speech detection voice_capture_thread = Thread(target=subrecord.voice_capture, args=[math.floor(RECORD_KHZ *1000), INPUT_BUF_SIZE, voice_data_queue]) voice_capture_thread.start() while True: speech.wav = voice_data_queue.get() WAV_FILE = path.join(path.dirname(path.realpath(__file__)), "speech.wav") r = sr.Recognizer() with sr.WavFile(WAV_FILE) as source: audio = r.record(source) try: result_text = r.recognize_google(audio) #result_text is a string print(result_text) #convert string to list result_list = result_text.split() #word frequency counting for word in result_list: if word == word_to_detect: TOTAL_WORD_COUNT += 1 print("Has appreared %d times", TOTAL_WORD_COUNT) except sr.UnknownValueError: print("Google Speech Reconition could not uderstand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e))
def __init__(self, num_threads): assert(num_threads > 0) self.thread_pool = [] self.num_threads = num_threads # Create threads and add to the thread pool for i in range(num_threads): thread = Thread.Thread(i) self.add_thread(thread)
def on_pushButton_5_clicked(self): self.thread = Thread.Thread(self.dataset, self.centerpts) self.pushButton_5.setEnabled(False) self.axes1 = self.figure1.add_subplot() self.axes1.clear() self.thread.signal.connect(self.Update) self.thread.finish.connect(self.buttonEnable) self.thread.start()
def add_thread(self, thread_path, thread_name=None): """ Add a Messenger thread representing a conversation if thread_name is provided, label the thread as thread_name """ new_thread = Thread(thread_path) if thread_name: self.threads[thread_name] = new_thread else: self.threads[new_thread.title] = new_thread
def Process_2(self): self.ConfirmBtn_9.setEnabled(False) img_path = self.lineEdit_24.text() save_path = self.lineEdit_25.text() #requirement4_3.warpaffine(img_path, save_path) self.t7 = Thread.R7Thread(img_path, save_path) self.t7.Daemon = True self.t7._signal.connect(self.set_btn_4) self.t7._signal2[str].connect(self.Event) self.t7.start()
def Process_3(self): self.ConfirmBtn_10.setEnabled(False) file_path = self.lineEdit_26.text() save_path = self.lineEdit_27.text() #requirement4_4.main(file_path, save_path) self.t8 = Thread.R8Thread(file_path, save_path) self.t8.Daemon = True self.t8._signal.connect(self.set_btn_5) self.t8._signal2[str].connect(self.Event) self.t8._signal3.connect(self.Update_2) self.t8.start()
def Confirm_8(self): self.ConfirmBtn_12.setEnabled(False) file_name = self.lineEdit_34.text() mp3_file = self.lineEdit_35.text() path_save = self.lineEdit_36.text() #vedioAudio.video_add_mp3(file_name, mp3_file, path_save) self.t13 = Thread.R13Thread(file_name, mp3_file, path_save) self.t13.Daemon = True self.t13._signal.connect(self.set_btn_11) self.t13._signal2[str].connect(self.Event) self.t13.start()
def Confirm_6(self): self.ConfirmBtn_6.setEnabled(False) img_path = self.lineEdit_19.text() logo_path = self.lineEdit_20.text() save_path = self.lineEdit_30.text() # requirement6.pic_water(img_path, logo_path, save_path) self.t11 = Thread.R11Thread(img_path, logo_path, save_path) self.t11.Daemon = True self.t11._signal.connect(self.set_btn_9) self.t11._signal2[str].connect(self.Event) self.t11._signal3.connect(self.Update_5) self.t11.start()
def Process_4(self): self.ConfirmBtn_5.setEnabled(False) path_green = self.lineEdit_17.text() path_bg = self.lineEdit_18.text() path_save = self.lineEdit_28.text() #requirement7.delgreen(path_green, path_bg, path_save) self.t9 = Thread.R9Thread(path_green, path_bg, path_save) self.t9.Daemon = True self.t9._signal.connect(self.set_btn_6) self.t9._signal2[str].connect(self.Event) self.t9._signal3.connect(self.Update_4) self.t9.start()
def on_pushButton(self): if self.label.text() == "Server Off": self.label.setText("Server On") self.Button_Server.setText("Off") self.TCP_Server.tcp_Flag = True print("Open TCP") self.TCP_Server.StartTcpServer() self.SendVideo = Thread(target=self.TCP_Server.sendvideo) self.ReadData = Thread(target=self.TCP_Server.readdata) self.power = Thread(target=self.TCP_Server.Power) self.SendVideo.start() self.ReadData.start() self.power.start() elif self.label.text() == 'Server On': self.label.setText("Server Off") self.Button_Server.setText("On") self.TCP_Server.tcp_Flag = False try: stop_thread(self.ReadData) stop_thread(self.power) stop_thread(self.SendVideo) except: pass self.TCP_Server.StopTcpServer() print("Close TCP")
class myserver(): def __init__(self): self.TCP_Server = Server() self.TCP_Server.StartTcpServer() self.ReadData = Thread(target=self.TCP_Server.readdata) self.SendVideo = Thread(target=self.TCP_Server.sendvideo) self.power = Thread(target=self.TCP_Server.Power) self.SendVideo.start() self.ReadData.start() self.power.start() def close(self): try: stop_thread(self.SendVideo) stop_thread(self.ReadData) stop_thread(self.power) except: pass try: self.TCP_Server.server_socket.shutdown(2) self.TCP_Server.server_socket1.shutdown(2) self.TCP_Server.StopTcpServer() except: pass print("Close TCP") os._exit(0)
def __init__(self): self.user_ui = True self.start_tcp = False self.TCP_Server = Server() self.parseOpt() if self.user_ui: self.app = QApplication(sys.argv) super(mywindow, self).__init__() self.setupUi(self) self.m_DragPosition = self.pos() self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint) self.setMouseTracking(True) self.Button_Server.setText("On") self.on_pushButton() self.Button_Server.clicked.connect(self.on_pushButton) self.pushButton_Close.clicked.connect(self.close) self.pushButton_Min.clicked.connect(self.windowMinimumed) if self.start_tcp: self.TCP_Server.StartTcpServer() self.ReadData = Thread(target=self.TCP_Server.readdata) self.SendVideo = Thread(target=self.TCP_Server.sendvideo) self.power = Thread(target=self.TCP_Server.Power) self.SendVideo.start() self.ReadData.start() self.power.start() if self.user_ui: self.label.setText("Server On") self.Button_Server.setText("Off")
def main(): global found global fail parser = optparse.OptionParser( "Usage: -H <HostName> -U <Username> -P <Password") parser.add_option( "-H", dest="thost", type="string", help="Enter the Host on which you want brute force ssh login") parser.add_option( "-U", dest="username", type="string", help="Enter the username that on which you want to brute force") parser.add_option( "-P", dest="passfile", type="string", help="Enter the password file which can be used for bruteforcing attack" ) (options, args) = parser.parse_args() if options.thost == None or options.username == None or options.passfile == None: print parser.usage exit(0) thost = options.thost username = options.username passfile = options.passfile f = open(passfile, "r") for line in f.readlines(): if fail > 5: print "Too many timeouts" exit(0) connections_lock.acquire() password = line.strip("\n") print " The password used in this iteration is %s " % password t = Thread(target=connect, args=(thost, username, password, True)) t.start()
def watch(self, interval): thread = Thread(target=self.run, args=(self, interval,)) thread.daemon = True thread.start()