def main(): while True: message = urllib.request.urlopen("http://127.0.0.1:8765/grep").read() try: parse(message) except Exception as e: __builtin__.original_print('parse exc: ' + str(e))
def sendText(text): try: response = pythonbridgeextension.post(json.dumps(text)) except Exception as e: __builtin__.original_print('sendText exception: ' + str(e)) print(traceback.format_exc()) finally: pass
async def sendText(text): try: r = http.request('POST', 'http://127.0.0.1:8765/post', headers={'Content-Type': 'application/json'}, body=text) except Exception as e: __builtin__.original_print('send exception: ' + str(e)) finally: pass
def send(text): if isinstance(text, dict): try: text = json.dumps(text) except Exception as e: __builtin__.original_print('json.dumps failed: ' + str(e)) loop = None try: loop = asyncio.get_event_loop() except: pass if not loop: loop = asyncio.new_event_loop() if loop.is_running(): def async_print(text): send(text) thread = threading.Thread(target=async_print, args=[text]) thread.start() thread.join() else: loop.run_until_complete(sendText(text))
def dprint(text): __builtin__.original_print(text)
def dprint(*args, **kwargs): text = '' + str(*args) # + ' ' + str(kwargs) __builtin__.original_print('' + str(*args), **kwargs) if patcher: patcher.callback(text)
def print(*args) -> None: original_print(*args, file=stderr, flush=True)