Skip to content

Commit

Permalink
Fixed sanic to run in different process.
Browse files Browse the repository at this point in the history
  • Loading branch information
natfarleydev committed Jan 20, 2017
1 parent b56de0d commit 880c87e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
3 changes: 2 additions & 1 deletion beards/apibeard/apibeard.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import functools
import re

from skybeard.beards import BeardChatHandler, regex_predicate
from skybeard.beards import BeardChatHandler
from skybeard.predicates import regex_predicate
from skybeard.decorators import onerror, debugonly

from . import server
Expand Down
34 changes: 17 additions & 17 deletions beards/apibeard/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,24 @@ def start(debug=False):
Returns the started process.
"""
# global proc
# proc = Process(
# target=_start_server,
# args=(
# app,
# ),
# kwargs=dict(
# debug=debug,
# after_start=setup_telegram
# )
# )
# proc.start()
# return proc
import logging
logger = logging.getLogger("async_sanic")
global proc
proc = Process(
target=_start_server,
args=(
app,
),
kwargs=dict(
debug=debug,
after_start=setup_telegram
)
)
proc.start()
return proc
# import logging
# logger = logging.getLogger("async_sanic")

coro = run_web_app(app, 8000, loop=asyncio.get_event_loop(), logger=logger)
return asyncio.ensure_future(coro)
# coro = run_web_app(app, 8000, loop=asyncio.get_event_loop(), logger=logger)
# return asyncio.ensure_future(coro)


def stop():
Expand Down
10 changes: 5 additions & 5 deletions beards/apibeard/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from sanic.response import json, text
from sanic.exceptions import NotFound

try:
from sanic_cors import CORS
except ImportError:
assert False, "Missing dependency (sanic_cors). To install: pip install https://github.com/ashleysommer/sanic-cors/"
# try:
# from sanic_cors import CORS
# except ImportError:
# assert False, "Missing dependency (sanic_cors). To install: pip install https://github.com/ashleysommer/sanic-cors/"

from skybeard.beards import Beard

Expand All @@ -22,7 +22,7 @@
app = Sanic(__name__)

# CORS: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
CORS(app)
# CORS(app)
key_blueprint = Blueprint('key', url_prefix='/key[A-z]+')


Expand Down

0 comments on commit 880c87e

Please sign in to comment.