在Mac OS X上使用Python产生新的非阻塞过程 [英] Spawn a new non-blocking process using Python on Mac OS X

查看:102
本文介绍了在Mac OS X上使用Python产生新的非阻塞过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些文章,甚至出现了关于该主题的文章| 溢出问题,但是我仍然做不到.

I found some articles and even stack|overflow questions addressing this subject, but I still can't do it..

我想做的是从python打开一个firefox实例.那么python应用程序应继续关注自己的事务,并忽略firefox进程.

What I want to do is open an instance of firefox from python. then the python application should keep minding its own business and ignore the firefox process.

我能够使用以下方法在Windows-7和XP上实现这一目标:

I was able to achive this goal on Windows-7 and XP using:

subprocess.Popen()

在OS X上,我尝试过:

On OS X I tried:

subprocess.Popen(['/Applications/Firefox.app/Contents/MacOS/firefox-bin'])
subprocess.call(['/Applications/Firefox.app/Contents/MacOS/firefox-bin'])
subprocess.call(['/Applications/Firefox.app/Contents/MacOS/firefox-bin'], shell=True)
os.system('/Applications/Firefox.app/Contents/MacOS/firefox-bin') 

(可能还有一些我忘了的其他)无济于事.我的python应用程序冻结,直到我关闭firefox应用程序为止.

(and probably some others I forgot) to no avail. My python app freezes till I go and close the firefox app.

我在这里想念什么?有任何线索吗?

推荐答案

您需要以某种方式分离该过程.我从从python生成过程中抢夺了这个

You'll need to detach the process somehow. I snatched this from spawning process from python

import os
pid = os.fork()
if 0 == pid:
  os.system('firefox')
  os._exit(0)
else:
  os._exit(0)

这会生成同一脚本的分叉的无头版本,然后可以执行您喜欢的任何操作,然后直接退出.

This spawns a forked headless version of the same script which can then execute whatever you like and quit directly afterwards.

这篇关于在Mac OS X上使用Python产生新的非阻塞过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆