首页 文章

在Xcode中运行iOS项目之前运行python HttpServer

提问于
浏览
0

我想在运行iOS项目之前运行一个http服务器 . 我在 Run Script 中添加了一个脚本 python -m SimpleHTTPServer 9527 .
enter image description here
当我在终端中运行它时没关系,但当我点击Xcode中的 Run 按钮时,它停止了

enter image description here

当我停止项目时,Xcode显示了一些错误日志:

在0.0.0.0端口9527上提供HTTP ... Traceback(最近一次调用最后一次):文件"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py",第162行,在_run_module_as_main“ main ", fname, loader, pkg_name) File " /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /runpy.py ", line 72, in _run_code exec code in run_globals File " /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SimpleHTTPServer.py ", line 235, in test() File " /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /SimpleHTTPServer.py ", line 231, in test BaseHTTPServer.test(HandlerClass, ServerClass) File " /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/BaseHTTPServer.py ", line 599, in test httpd.serve_forever() File " /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /SocketServer.py ", line 236, in serve_forever poll_interval) File " /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py“,第155行,在_eintr_retry中返回func(* args)KeyboardInterrupt

请帮助或尝试提供一些如何实现这一目标的想法 . 提前致谢 .

1 回答

  • 1

    您的构建仍处于此阶段,因为您执行的命令在您请求之前不会终止 . 最有可能的是,Web服务器正在正常运行,但Xcode正在等待它终止,直到您单击“停止”按钮才能执行此操作 .

    当您在Python中停止内置Web服务器时,您看到的堆栈跟踪是正常的 . 如果在使用终端时使用CTRL C退出,则会看到类似的消息 .

    通常,构建的“执行shell”阶段应运行执行任务然后自行退出的命令,但是如果您尝试在构建期间运行Web服务器,则需要使用两个阶段 . 构建开始时的一个阶段是启动Web服务器并将其分叉,另一个阶段在构建结束时终止它 . 虽然根据我的经验,变量不会在构建的阶段之间保持不变,但您可以将PID写入文件,然后在稍后的阶段中读取它 .

    除了这个解决方案之外,如果您需要在构建过程中运行服务器,我建议您重新考虑 . 如果您将来开始使用Continuous Integration中的一些,或者只是想同时运行多个构建,分配端口号的其他复杂性将带来挑战 .

相关问题