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

问题描述 投票:-1回答:2

我正在使用Stanford Core NLP Server。我想从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.

如何让我的服务器运行而不是在线路过后关闭?

python server
2个回答
1
投票

看起来像一个更简单的错误:

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

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


1
投票

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

它说端口已经被使用,尝试使用launch_NLP.bat中的不同端口,如9001。

© www.soinside.com 2019 - 2024. All rights reserved.