Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In python, how can I do a non-blocking system call?

Tags:

python

In Python, is it possible to do a non-blocking system call without forking off a thread? i.e., can I avoid:

import thread
thread.start_new_thread(os.system,('cmd',))
like image 611
Ross Rogers Avatar asked Oct 23 '09 14:10

Ross Rogers


1 Answers

Use the subprocess module (Popen) and have the result written to a file. You can either "wait" for the subprocess to terminate or proceed with other business and poll for the result in the file etc.

like image 101
jldupont Avatar answered Sep 29 '22 00:09

jldupont