如何使用python代码启动服务器?

时间:2019-04-01 12:13:30

标签: python server

我正在使用Stanford Core NLP服务器。我想从python文件启动它。

要从命令提示符启动它,我使用:

cd C:\ProgramData\Anaconda3\stanford-corenlp-full-2018-10-05
java -mx1g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -tiemout 15000

我尝试从包含以下代码的 python文件启动它:

import subprocess
subprocess.call([r'C:\Users\maell\PycharmProjects\Preprocessing\launch_NLP.bat'])

带有包含以下内容的launch_NLP.bat:

cd C:\ProgramData\Anaconda3\stanford-corenlp-full-2018-10-05
java -mx1g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -tiemout 15000

输出如下:

C:\Users\maell\PycharmProjects\Pre-processing>cd                     
C:\ProgramData\Anaconda3\stanford-corenlp-full-2018-10-05 

C:\ProgramData\Anaconda3\stanford-corenlp-full-2018-10-05>java -mx1g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer -port 9000 -tiemout 15000 
[main] INFO CoreNLP - --- StanfordCoreNLPServer#main() called ---
[main] INFO CoreNLP - setting default constituency parser
[main] INFO CoreNLP - warning: cannot find edu/stanford/nlp/models/srparser/englishSR.ser.gz
[main] INFO CoreNLP - using: edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz instead
[main] INFO CoreNLP - to use shift reduce parser download English models jar from:
[main] INFO CoreNLP - http://stanfordnlp.github.io/CoreNLP/download.html
[main] INFO CoreNLP -     Threads: 12
[main] INFO CoreNLP - Starting server...
java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.Net.bind(Unknown Source)
    at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
    at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
    at sun.net.httpserver.ServerImpl.<init>(Unknown Source)
    at sun.net.httpserver.HttpServerImpl.<init>(Unknown Source)
    at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(Unknown Source)
    at com.sun.net.httpserver.HttpServer.create(Unknown Source)
    at edu.stanford.nlp.pipeline.StanfordCoreNLPServer.run(StanfordCoreNLPServer.java:1427)
    at edu.stanford.nlp.pipeline.StanfordCoreNLPServer.main(StanfordCoreNLPServer.java:1523)
[Thread-0] INFO CoreNLP - CoreNLP Server is shutting down.

如何让我的服务器运行,并且在线路经过后不关闭?

2 个答案:

答案 0 :(得分:1)

似乎是一个更简单的错误:

java.net.BindException: Address already in use: bind

要么终止在端口9000上运行的进程,要么在另一个端口上运行的进程,下一次应该可以运行。

答案 1 :(得分:1)

  

java.net.BindException:地址已在使用中:bind

该端口已被使用,请尝试使用launch_NLP.bat中的另一个端口(例如9001)。