私は、ユーザーに2つのオプションを提供するpythonスクリプトを書いています。 1つの選択肢では、ユーザ入力は、バックグラウンドで機能を実行するために使用される。他の例では、ユーザ入力は、フォアグラウンドで機能を実行するために使用される。私はどうすれば両方を達成できますか?私はバックグラウンドで完全なスクリプトを実行するために "nohup"コマンドを使用したくありません。私は、ある機能をバックグラウンドで実行したいだけです。バックグラウンドでPythonコードの一部を実行する
私はまた、バックグラウンドプロセスがユーザーの意志で止まることを望みます。ここで
は、私が何をしたいの小さなサンプルです:
def display():
cnt = 1
a = []
if len(live_matches) == 0:
print "sorry, no live matches currently"
else:
for match in live_matches:
print str(cnt) + "." + match['mchdesc'] + "," + match['mnum']
a[cnt] = match
cnt = cnt + 1
choice = raw_input("Enter the match numbers for live updates separated by spaces")
for c in choice.split(' '):
update_matches.append(a[int(c)])
if len(update_matches) > 0:
#call some function and run in background
cnt = 1
for match in completed_matches:
print str(cnt) + "." + match['mchdesc'] + "," + match['mnum']
cnt = cnt + 1
choice = raw_input("enter the match number for scorecard")
#call some function again but run it in foreground
[Celery](http://www.celeryproject.org/) – Harrison
[マルチプロセッシング](https://docs.python.org/2/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing )標準のPythonモジュールで、バックグラウンドで関数を実行します。 – mguijarr
これらの機能を非同期/同期で実行することを意味しますか? – danielfranca