首页 > 编程语言 >python subprocess Popen非阻塞,读取adb日志

python subprocess Popen非阻塞,读取adb日志

时间:2023-04-26 11:35:21浏览次数:53  
标签:__ stdout python Popen subprocess adb line True

简单版

from threading  import Thread
from queue import Queue, Empty
import shlex
if __name__ == '__main__':
    print_hi('PyCharm')

    # Car().run()

    def enqueue_output(stdout, queue):
        with open("www.log", 'wb+') as wwwf:
            for line in iter(stdout.readline,b''):
                # print("line",line)
                wwwf.write(line)
                queue.put(line)


    subprocess.Popen("adb logcat -c", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, close_fds=True)
    process = subprocess.Popen("adb logcat", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, close_fds=True)

    q = Queue()
    t = Thread(target=enqueue_output, args=(process.stdout, q))

    t.daemon = True  # thread dies with the program
    t.start()

    try:
        # line = q.get_nowait()  # or q.get(timeout=.1)
        line =  q.get(timeout=3)  # or q.get(timeout=.1)
    except Empty:
        print('no output yet')
    else:  # got line
        input("请输入:")

封装版

 

标签:__,stdout,python,Popen,subprocess,adb,line,True
From: https://www.cnblogs.com/huyangblog/p/17346786.html

相关文章

  • python安装过程中的问题
    1.用pip安装插件时报Fatalerrorinlauncher:Unabletocreateprocessusing'"D:\ProgramFiles\Python311\python.exe""D:\ProgramFiles\Python311\Scripts\pip.exe"installpyinstaller':???????????解决:1.检查Python安装的路径是否正确。在这种......
  • 一篇文章教会你什么是Python模仿强类型
    今日鸡汤此曲只应天上有,人间难得几回闻。前言   Hi,各位小伙伴,你们好,今天我们来说一个Python未来趋势的并且一个好玩的东西。    我们可能多多少少都听过一句话,动态一时爽,重构火葬场。从生产角度出发,Python确实是一门很优秀的语言,但是当多人协作时,或者接手别人Python代码时,......
  • 力扣 819. 最常见的单词--python
    给定一个段落(paragraph)和一个禁用单词列表(banned)。返回出现次数最多,同时不在禁用列表中的单词。题目保证至少有一个词不在禁用列表中,而且答案唯一。禁用列表中的单词用小写字母表示,不含标点符号。段落中的单词不区分大小写。答案都是小写字母。 示例:输入:paragraph......
  • python 使用selenium 不开启浏览器
    selenium不启动浏览器模式打开浏览器再启动会浪费时间,对爬虫的性能也是个影响,还有一种就是不打开浏览器。如下参数是针对chrome的全局参数,不能自定义参数。fromseleniumimportwebdriver#还有一些其他的参数'''#添加UAoptions.add_argument('user-agent="MQQBrowser/26......
  • Python的socket编程
    目前处在学习python爬虫的阶段,昨天看到了python的socket模块,分别实现TCP、UDP时间戳回显。1、tcp通信server和client代码#tcpServer.py#!/usr/bin/python#-*-coding:utf-8-*-fromsocketimport*fromtimeimportctimeHOST=''PORT=21156BUFSIZE=1024ADD......
  • python open 用法
    函数语法open(file,mode,buffering,encoding,errors,newline,closefd,opener)参数说明:name:一个包含了你要访问的文件名称的字符串值。mode:mode决定了打开文件的模式:只读,写入,追加等。所有可取值见如下的完全列表。这个参数是非强制的,默认文件访问模式为只读......
  • python 快速替换csv数据集字符串列表中的表情符号为空,asyncio,re,pandas
     传统的字符串列表替换字符串使用遍历非常慢比如下面这段代码,如果处理几十万或上百万的数据集时,会非常的慢,几小时几天都可能importrep=re.compile(u'['u'\U0001F300-\U0001F64F'u'\U0001F680-\U0001F6FF'u'\u2600-\u2B55\U00010000-\U0010ffff]+')#text="超详细修......
  • python安装pillow报错
    Fatalerrorinlauncher:Unabletocreateprocessusing'"D:\ProgramFiles\Python311\python.exe" "D:\ProgramFiles\Python311\Scripts\pip.exe"installpillow':??????????? 解决:cmd窗口执行32位:python3-mpipinstall--up......
  • Python爬虫基础之三
    Python爬虫基础包括HTTP协议、HTML、CSS和JavaScript语言基础、requests库的使用、BeautifulSoup库的使用、xpath和正则表达式的使用等。此外,还应该了解反爬虫机制和爬虫的一些常见问题及解决方法。上一篇文章讲解了有关条件判断语句、循环语句、元组、字典等相关知识,本节将围绕......
  • python 画思维导图
    1.安装Graphviz要安装Graphviz,可以按照以下步骤操作:前往Graphviz官网前往Graphviz官网(https://graphviz.org/)。https://graphviz.org/download/下载适合你操作系统的安装文件在官网首页中,你可以看到Windows、macOS和Linux三个操作系统的图标。选择适合你操作系统......