通過Ubuntu系統上的命令行(/ bin/sh),我執行了一個使用multiprocessing.Process()啓動另一個Python3腳本的Python3腳本。我收到以下錯誤消息:從另一個腳本啓動Python腳本 - 奇怪行爲
[email protected]:/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)
[email protected]:/media/collier/BETABOTS/Neobot$ python3 -c "import os; os.system('./conf/set_data.py3')" #WORKS
[email protected]:/media/collier/BETABOTS/Neobot$ ./conf/set_data.py3 #WORKS
問題是 - 爲什麼這不起作用?它應該啓動第二個腳本,並繼續執行出問題。
我對試圖解決問題的代碼進行了編輯。 錯誤現在在第13行。同樣的錯誤發生在第12行「JOB_CONFIG = multiprocessing.Process(os.system('date')); JOB_CONFIG.start()」,我用它作爲測試行。我將第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()
您不會因爲憤怒而放棄問題而傷害任何人。相反,你應該[改進問題](http://meta.stackexchange.com/a/194077/185951)。 –
你提到你得到一個錯誤。是這樣嗎?什麼是錯誤? –