2012/6/13 Valerio Pachera siri...@gmail.com
Ciao a tutti, sto creando uno script che lancia mplayer quando si
verifica una certa condizione.
Se lancio lo script in foreground, maplayer funziona, altrimenti
rimane come in sospeso.
Per eseguire il comando uso il modulo 'commands'.
Nota che il modulo commands è deprecato nelle ultime versioni di python:
- http://docs.python.org/library/commands.html
Secondo me devi usare Popen nel modulo subprocess.
Prova per esempio a digitare sull'interprete interattivo di python:
import subprocess
p = subprocess.Popen(['sleep', '10'])
Vedrai che il comando sleep viene lanciato in background, senza bloccare
l'interprete. Non ho capito se è questo quello che chiedi, peró ti dovrebbe
essere utile :-)
Maggiori info:
- http://docs.python.org/library/subprocess.html
Bastano 2 righe per fare una prova:
---
import commands
commands.getstatusoutput ('mplayer /usr/share/sounds/k3b_success1.wav')
---
python -u prova.py
e
python -u prova.py
Ho provato anche a forkare il processo ma ottengo lo stesso risultato
---
def play_sound(sound):
print sound
commands.getstatusoutput ('mplayer '+ sound )
player = multiprocessing.Process ( target=play_sound,
args=(/usr/share/sounds/k3b_success1.wav,) )
player.start()
---
Premetto che non sono un programmatore e python lo conosco parzialmente.
Grazie, ciao.
___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python
--
Giovanni Dall'Olio, phd student
IBE, Institut de Biologia Evolutiva, CEXS-UPF (Barcelona, Spain)
My blog on bioinformatics: http://bioinfoblog.it
___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python