相关疑难解决方法(0)

.exe中的Python子进程

我正在创建一个python脚本,它将通过网络复制文件和文件夹.它是跨平台的所以我使用cx_freeze创建一个.exe文件

我使用了子进程模块的Popen方法

如果我运行.py文件它正在按预期运行但是当我创建.exe子进程没有在系统中创建

我已经浏览了子进程模块的所有文档,但我没有找到任何解决方案

其他一切(我使用Tkinter也工作正常)正在.exe接受子进程中工作.

任何想法如何在.exe.file中调用子进程?

此文件正在调用另一个.py文件

def start_scheduler_action(self, scheduler_id, scheduler_name, list_index):
       scheduler_detail=db.get_scheduler_detail_using_id(scheduler_id)
        for detail in scheduler_detail:
            source_path=detail[2]
        if not os.path.exists(source_path):
            showerror("Invalid Path","Please select valid path", parent=self.new_frame)
            return

        self.forms.new_scheduler.start_scheduler_button.destroy()

        #Create stop scheduler button
        if getattr(self.forms.new_scheduler, "stop_scheduler_button", None)==None:

            self.forms.new_scheduler.stop_scheduler_button = tk.Button(self.new_frame, text='Stop scheduler', width=10, command=lambda:self.stop_scheduler_action(scheduler_id, scheduler_name, list_index))
            self.forms.new_scheduler.stop_scheduler_button.grid(row=11, column=1, sticky=E, pady=10, padx=1)

        scheduler_id=str(scheduler_id)

        # Get python paths
        if sys.platform == "win32":
            proc = subprocess.Popen(['where', "python"], env=None, stdout=subprocess.PIPE)

        else:
            proc = subprocess.Popen(['which', "python"], env=None,stdout=subprocess.PIPE)

        out, err …
Run Code Online (Sandbox Code Playgroud)

python subprocess network-programming python-2.7 python-3.x

10
推荐指数
1
解决办法
1006
查看次数

os.popen在Python 2.6中是否真的被弃用了?

在线文档声明os.popen现已弃用.所有其他已弃用的函数都会适当地提高DeprecationWarning.例如:

>>> import os
>>> [c.close() for c in os.popen2('ps h -eo pid:1,command')]
__main__:1: DeprecationWarning: os.popen2 is deprecated.  Use the subprocess module.
[None, None]
Run Code Online (Sandbox Code Playgroud)

另一方面,函数os.popen以静默方式完成:

>>>len(list(os.popen('ps h -eo pid:1,command')))
202
Run Code Online (Sandbox Code Playgroud)

没有提出警告.在三种可能的情况中

  1. 文档和标准库对弃用的内容有不同的看法;
  2. 文档中有一个错误,os.popen并没有真正弃用;
  3. 标准库中存在错误,os.popen应该发出警告;

哪一个是正确的?

有关背景信息,请参阅我正在使用的Python:

>>> import sys
>>> print sys.version
2.6.2 (r262:71600, May 12 2009, 10:57:01) 
[GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)]
Run Code Online (Sandbox Code Playgroud)

os.popen的参数取自在Stack Overflow上的回复.

附录:感谢下面的 cobbal ,事实证明os.popen在Python 3.1中并没有被弃用.

python std deprecated

7
推荐指数
2
解决办法
6721
查看次数

检查Rhythmbox是否通过Python运行

我试图从Rhythmbox中提取信息dbus,但我只想这样做,如果Rhythmbox正在运行.有没有办法检查Rhythmbox是否通过Python运行而不启动它如果没有运行?

每当我调用这样的dbus代码时:

bus = dbus.Bus()
obj = bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
iface = dbus.Interface(obj, "org.gnome.Rhythmbox.Shell)
Run Code Online (Sandbox Code Playgroud)

并且Rhythmbox没有运行,然后启动它.

dbus如果Rhythmbox在没有实际启动的情况下运行,我可以通过检查吗?或者除了解析当前正在运行的进程列表之外,还有其他方法吗?

python dbus rhythmbox

4
推荐指数
1
解决办法
1565
查看次数