Subprocess.Popen(cmd2,stdout=subprocess.PIPE, stderr=subprocess.PIPE), Subprocess.Popen(cmd1,stdout=subprocess.PIPE, stderr=subprocess.PIPE), Using Popen, you can then keep stdout and stderr inside your object, and then use them later, without having to rely on a file: p = subprocess.Popen(cmd,stdout=subprocess.PIPE, stderr=subprocess.PIPE)Īnother potential advantage of this method is that you could run multiple instances of Popen without waiting for completion instead of having a thread pool: processes=[ The difference is that call waits for completion (is blocking) while Popen is not, see What's the difference between subprocess Popen and call (how can I use them)? Subprocess.call(cmd, stdout=fout, stderr=ferr)Īnother option would be to use Popen instead of call. You can indeed associate stdin and stdout to files, as in the answer from fout = open('stdout.txt','w') Shell_command = "%s %s %s %s %s" % (command,name,rc,seed,cdir) Pool_args = zip(trial_ids,run_types,self._population) I should mention I have a bot running the game, so I don't want any actual interaction from the user's end to occur. My understanding was that shell=True should be spawning a sub-shell, but I guess I it is spawning one in a way that is shared between each call. Is there a better way to handle highly-interactive shells than this? I'd considered kicking off a screen for each instance, but thought there was a cleaner way. I have the code I normally use for this kind of thing, with crawl replacing other applications I've thrown a GA at. However, with dcss being quite interactive having a shared subshell seems to be problematic. In the past when I've used a pool to evaluate similar code (genetic algorithms), I've used subprocess.call to split off each process. Continued abuse of our services will cause your IP address to be blocked indefinitely.I am trying to run multiple instances of a console-based game (dungeon crawl stone soup - for research purposes naturally) using a multiprocessing pool to evaluate each run. Please fill out the CAPTCHA below and then click the button to indicate that you agree to these terms. If you wish to be unblocked, you must agree that you will take immediate steps to rectify this issue. If you do not understand what is causing this behavior, please contact us here. If you promise to stop (by clicking the Agree button below), we'll unblock your connection for now, but we will immediately re-block it if we detect additional bad behavior.
0 Comments
Leave a Reply. |