从另一个奇怪的行为中启动Python脚本

时间:2013-08-17 20:57:11

标签: multithreading python-3.x multiprocessing

通过Ubuntu系统上的命令行(/ bin / sh),我执行了一个Python3脚本,该脚本使用multiprocessing.Process()来启动另一个Python3脚本。我收到以下错误消息:

collier@Nacho-Laptop:/media/collier/BETABOTS/Neobot$ ./Betabot #THE SECOND SCRIPT NEVER EXECUTES
/bin/sh: 1: Syntax error: "(" unexpected (expecting "}")
Traceback (most recent call last):
  File "./Betabot", line 26, in <module>
    JOB_CONFIG = multiprocessing.Process(os.system('./conf/set_data.py3'))
  File "/usr/lib/python3.3/multiprocessing/process.py", line 72, in __init__
    assert group is None, 'group argument must be None for now'
AssertionError: group argument must be None for now

#TESTING THE SECOND SCRIPT BY ITSELF IN TWO WAYS (both work)
collier@Nacho-Laptop:/media/collier/BETABOTS/Neobot$ python3 -c "import os; os.system('./conf/set_data.py3')" #WORKS
collier@Nacho-Laptop:/media/collier/BETABOTS/Neobot$ ./conf/set_data.py3 #WORKS

问题是 - 为什么这不起作用?它应该启动第二个脚本,并继续执行而没有问题。

我对试图解决问题的代码进行了编辑。 错误现在在第13行。第12行出现相同的错误“JOB_CONFIG = multiprocessing.Process(os.system('date')); JOB_CONFIG.start()”我用作测试行。< / strong>我将第12行更改为“os.system('date')”并且可以正常工作,因此错误在于多处理命令

#!/usr/bin/env python3
import os, subprocess, multiprocessing
def write2file(openfile, WRITE):
    with open(openfile, 'w') as file:
        file.write(str(WRITE))
writetofile = writefile = filewrite = writer = filewriter = write2file
global BOTNAME, BOTINIT
BOTNAME = subprocess.getoutput('cat ./conf/startup.xml | grep -E -i -e \'<property name=\"botname\" value\' | ssed -r -e "s|<property name=\"botname\" value=\"(.*)\"/>|\1|gI"')
BOTINIT = os.getpid()

###Setup science information under ./mem/###
JOB_CONFIG = multiprocessing.Process(os.system('date')); JOB_CONFIG.start()
JOB_CONFIG = multiprocessing.Process(os.system('./conf/set_data.py3')); JOB_CONFIG.start()
###START###
write2file('./mem/BOTINIT_PID', BOTINIT); write2file('./mem/tty', os.ctermid()); write2file('./mem/SERVER_PID', BOTINIT)
JOB_EMOTION = multiprocessing.Process(os.system('./lib/emoterm -T Emotion -e ./lib/Emotion_System')); JOB_EMOTION.start()
JOB_SENSORY = multiprocessing.Process(os.system('./lib/Sensory_System')); JOB_SENSORY.start()
print(BOTNAME + ' is starting'); JOB_CONFIG.join()
try:
    os.system('./lib/neoterm -T' + BOTNAME + ' -e ./lib/beta_engine')
except:
    print('There seems to be an error.'); JOB_EMOTION.join(); JOB_SENSORY.join(); exit()
JOB_EMOTION.join(); JOB_SENSORY.join(); exit()

1 个答案:

答案 0 :(得分:1)

从主脚本继续运行的Python3脚本启动Python3脚本时,必须执行如下命令:

JOB_CONFIG = subprocess.Popen([sys.executable, './conf/set_data.py3'])

文件名字符串是脚本。这是保存到变量以允许我稍后操作该过程。例如,当主脚本应该等待另一个脚本时,我可以使用命令“JOB_CONFIG.wait()”。

对于错误消息第一行中的hashpling,这是由于使用的第一个子进程命令中的语法错误。