def appProcess(inputQueeuChannel, outputQueeuChannel, eventLoop, clipboard): appState = AppState() put(outputQueeuChannel, appState.requestAddr()) windowState = Gui() # waitingD terminate = False itera = 0 step = time.time() # temporal solution while not (terminate): # print itera itera += 1 # for debuging windowState.updateWindowsAndDraw(appState) eventLoop.processEvents( QtCore.QEventLoop.WaitForMoreEvents ) # trigger the all the gui changes and blocks waiting for input, therefore, it is CRITICAL, # that whenever a new set of elements are added to the queeu, a void event is feeded into the # event loop, just to awake the thread. # For safety reasons, only a QThread can concurrently feed the event loop, therefore, the thread # adding element to the Queue shall be a QThread instead of a normal Thread if windowState.copy_to_clipboard: clipboard.setText(appState.lastAddr) windowState.copy_to_clipboard = False guiValue, terminate = windowState.getValues() if not guiValue is None: print guiValue commtValue = non_blocking_get(inputQueeuChannel) appState.updateAppState(commtValue) output = appState.getValues(guiValue) if terminate is True: put(outputQueeuChannel, None) else: if output != None: # we pass a None as termination signal put(outputQueeuChannel, output) if (time.time() - step >= 15) or ( not (windowState.payment is None) ): # While not async updates we have to poll :( step = time.time() # TODO: "Delete this and refactoorrrr" put(outputQueeuChannel, appState.getValues(("RE_SCAN", None)))
def comunicationProcess(inputQueeuChannel,outputQueeuChannel,event_loop): while True: elements = blocking_get_all(inputQueeuChannel) if shallTerminate(elements): break; else: for serial, element in elements: try: for addr in element.get('rescans',[]): put(outputQueeuChannel,{'rescan' : rescan(addr)}) event_loop.wakeUp() # it might be better just to use .flush() --- it might also works event_loop.wakeUp(), the documentation says nothing if 'payment' in element: tx = createTX(element['payment']) if tx is None: pass # TODO else: payload = {'hex':str(tx)} r = requests.post("https://testnet3.toshi.io/api/v0/transactions", data=json.dumps(payload)) print r.text print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" event_loop.wakeUp() except Exception as e: # TODO USE SPECIFIC EXCEPTIONS print "####################### EXCEPTION #############################" print e # do something here handleing the problem print ("And the serial number is %i"%serial) put(outputQueeuChannel,{'label' : serial} ) print "finnishing communication proccess"
def comunicationProcess(inputQueeuChannel, outputQueeuChannel, event_loop): while True: elements = blocking_get_all(inputQueeuChannel) if shallTerminate(elements): break else: for serial, element in elements: try: for addr in element.get("rescans", []): put(outputQueeuChannel, {"rescan": rescan(addr)}) event_loop.wakeUp() # it might be better just to use .flush() --- it might also works event_loop.wakeUp(), the documentation says nothing if "payment" in element: tx = createTX(element["payment"]) if tx is None: pass # TODO else: payload = {"hex": str(tx)} r = requests.post("https://testnet3.toshi.io/api/v0/transactions", data=json.dumps(payload)) print r.text print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" event_loop.wakeUp() except Exception as e: # TODO USE SPECIFIC EXCEPTIONS print "####################### EXCEPTION #############################" print e # do something here handleing the problem print ("And the serial number is %i" % serial) put(outputQueeuChannel, {"label": serial}) print "finnishing communication proccess"