Итак, я пытаюсь создать какой-то сервер python и использовать его с веб-сокетами (базовые c веб-сокеты, а не Flask или что-то еще). Я нашел этот вопрос и попытался сделать как в ответе, но не получил результата. Вот часть кода, где я создаю сервер и включаю его:
start_server = websockets.serve(hello, '0.0.0.0', os.environ['PORT'])
asyncio.get_event_loop().run_until_complete(start_server)
и вот логи heroku:
2020-02-02T19:15:18.488771+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [4] [INFO] Starting gunicorn 20.0.4
2020-02-02T19:15:18.489318+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [4] [INFO] Listening at: http://0.0.0.0:55677 (4)
2020-02-02T19:15:18.489403+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [4] [INFO] Using worker: sync
2020-02-02T19:15:18.493327+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [10] [INFO] Booting worker with pid: 10
2020-02-02T19:15:18.503354+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [11] [INFO] Booting worker with pid: 11
2020-02-02T19:15:18.598218+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [10] [ERROR] Exception in worker process
2020-02-02T19:15:18.598222+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.598223+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 1073, in create_server
2020-02-02T19:15:18.598225+00:00 app[web.1]: sock.bind(sa)
2020-02-02T19:15:18.598226+00:00 app[web.1]: OSError: [Errno 98] Address already in use
2020-02-02T19:15:18.598228+00:00 app[web.1]:
2020-02-02T19:15:18.598229+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-02-02T19:15:18.598230+00:00 app[web.1]:
2020-02-02T19:15:18.598232+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.598247+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-02-02T19:15:18.598249+00:00 app[web.1]: worker.init_process()
2020-02-02T19:15:18.598250+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-02-02T19:15:18.598251+00:00 app[web.1]: self.load_wsgi()
2020-02-02T19:15:18.598253+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-02-02T19:15:18.598254+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-02-02T19:15:18.598255+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-02-02T19:15:18.598257+00:00 app[web.1]: self.callable = self.load()
2020-02-02T19:15:18.598259+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-02-02T19:15:18.598260+00:00 app[web.1]: return self.load_wsgiapp()
2020-02-02T19:15:18.598261+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-02-02T19:15:18.598263+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-02-02T19:15:18.598264+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-02-02T19:15:18.598265+00:00 app[web.1]: mod = importlib.import_module(module)
2020-02-02T19:15:18.598267+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-02-02T19:15:18.598268+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-02-02T19:15:18.598270+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-02-02T19:15:18.598271+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-02-02T19:15:18.598273+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2020-02-02T19:15:18.598274+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2020-02-02T19:15:18.598275+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2020-02-02T19:15:18.598277+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-02-02T19:15:18.598278+00:00 app[web.1]: File "/app/run_server.py", line 27, in <module>
2020-02-02T19:15:18.598279+00:00 app[web.1]: asyncio.get_event_loop().run_until_complete(start_server)
2020-02-02T19:15:18.598281+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
2020-02-02T19:15:18.598282+00:00 app[web.1]: return future.result()
2020-02-02T19:15:18.598284+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/tasks.py", line 537, in _wrap_awaitable
2020-02-02T19:15:18.598285+00:00 app[web.1]: return (yield from awaitable.__await__())
2020-02-02T19:15:18.598287+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/server.py", line 965, in __await_impl__
2020-02-02T19:15:18.598288+00:00 app[web.1]: server = await self._create_server()
2020-02-02T19:15:18.598290+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 1077, in create_server
2020-02-02T19:15:18.598291+00:00 app[web.1]: % (sa, err.strerror.lower()))
2020-02-02T19:15:18.598293+00:00 app[web.1]: OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 55677): address already in use
2020-02-02T19:15:18.598565+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [10] [INFO] Worker exiting (pid: 10)
2020-02-02T19:15:18.601037+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [11] [ERROR] Exception in worker process
2020-02-02T19:15:18.601039+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.601041+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 1073, in create_server
2020-02-02T19:15:18.601042+00:00 app[web.1]: sock.bind(sa)
2020-02-02T19:15:18.601044+00:00 app[web.1]: OSError: [Errno 98] Address already in use
2020-02-02T19:15:18.601045+00:00 app[web.1]:
2020-02-02T19:15:18.601047+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-02-02T19:15:18.601048+00:00 app[web.1]:
2020-02-02T19:15:18.601050+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.601052+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-02-02T19:15:18.601053+00:00 app[web.1]: worker.init_process()
2020-02-02T19:15:18.601055+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-02-02T19:15:18.601056+00:00 app[web.1]: self.load_wsgi()
2020-02-02T19:15:18.601058+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-02-02T19:15:18.601059+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-02-02T19:15:18.601061+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-02-02T19:15:18.601062+00:00 app[web.1]: self.callable = self.load()
2020-02-02T19:15:18.601063+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-02-02T19:15:18.601065+00:00 app[web.1]: return self.load_wsgiapp()
2020-02-02T19:15:18.601066+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-02-02T19:15:18.601068+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-02-02T19:15:18.601069+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-02-02T19:15:18.601070+00:00 app[web.1]: mod = importlib.import_module(module)
2020-02-02T19:15:18.601072+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-02-02T19:15:18.601073+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-02-02T19:15:18.601075+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-02-02T19:15:18.601076+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-02-02T19:15:18.601078+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
2020-02-02T19:15:18.601079+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
2020-02-02T19:15:18.601081+00:00 app[web.1]: File "<frozen importlib._bootstrap_external>", line 678, in exec_module
2020-02-02T19:15:18.601082+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2020-02-02T19:15:18.601083+00:00 app[web.1]: File "/app/run_server.py", line 27, in <module>
2020-02-02T19:15:18.601085+00:00 app[web.1]: asyncio.get_event_loop().run_until_complete(start_server)
2020-02-02T19:15:18.601086+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 488, in run_until_complete
2020-02-02T19:15:18.601087+00:00 app[web.1]: return future.result()
2020-02-02T19:15:18.601089+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/tasks.py", line 537, in _wrap_awaitable
2020-02-02T19:15:18.601090+00:00 app[web.1]: return (yield from awaitable.__await__())
2020-02-02T19:15:18.601092+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/websockets/server.py", line 965, in __await_impl__
2020-02-02T19:15:18.601093+00:00 app[web.1]: server = await self._create_server()
2020-02-02T19:15:18.601095+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/asyncio/base_events.py", line 1077, in create_server
2020-02-02T19:15:18.601096+00:00 app[web.1]: % (sa, err.strerror.lower()))
2020-02-02T19:15:18.601098+00:00 app[web.1]: OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 55677): address already in use
2020-02-02T19:15:18.601406+00:00 app[web.1]: [2020-02-02 19:15:18 +0000] [11] [INFO] Worker exiting (pid: 11)
2020-02-02T19:15:18.639228+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.639258+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 209, in run
2020-02-02T19:15:18.639550+00:00 app[web.1]: self.sleep()
2020-02-02T19:15:18.639556+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 357, in sleep
2020-02-02T19:15:18.639766+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2020-02-02T19:15:18.639771+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-02-02T19:15:18.639932+00:00 app[web.1]: self.reap_workers()
2020-02-02T19:15:18.639937+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-02-02T19:15:18.640169+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-02-02T19:15:18.640215+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-02-02T19:15:18.640221+00:00 app[web.1]:
2020-02-02T19:15:18.640223+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2020-02-02T19:15:18.640224+00:00 app[web.1]:
2020-02-02T19:15:18.640227+00:00 app[web.1]: Traceback (most recent call last):
2020-02-02T19:15:18.640231+00:00 app[web.1]: File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2020-02-02T19:15:18.640350+00:00 app[web.1]: sys.exit(run())
2020-02-02T19:15:18.640355+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 58, in run
2020-02-02T19:15:18.640522+00:00 app[web.1]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2020-02-02T19:15:18.640527+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 228, in run
2020-02-02T19:15:18.640698+00:00 app[web.1]: super().run()
2020-02-02T19:15:18.640702+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 72, in run
2020-02-02T19:15:18.640826+00:00 app[web.1]: Arbiter(self).run()
2020-02-02T19:15:18.640831+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 229, in run
2020-02-02T19:15:18.640986+00:00 app[web.1]: self.halt(reason=inst.reason, exit_status=inst.exit_status)
2020-02-02T19:15:18.640990+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 342, in halt
2020-02-02T19:15:18.641179+00:00 app[web.1]: self.stop()
2020-02-02T19:15:18.641183+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 393, in stop
2020-02-02T19:15:18.641381+00:00 app[web.1]: time.sleep(0.1)
2020-02-02T19:15:18.641385+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2020-02-02T19:15:18.641543+00:00 app[web.1]: self.reap_workers()
2020-02-02T19:15:18.641547+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2020-02-02T19:15:18.641774+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2020-02-02T19:15:18.641801+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2020-02-02T19:15:19.000000+00:00 app[api]: Build succeeded
Если я правильно понимаю, мне нужно остановить процесс, который в данный момент работает на этом порту, и я просто не знаю, как.