Skip to content

Commit

Permalink
fix crash with no_yield being undefined, tinode#229
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed Apr 7, 2019
1 parent 7bb79ee commit dfe1b0f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 43 deletions.
8 changes: 4 additions & 4 deletions py_grpc/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
with open('README.md', 'r') as readme_file:
long_description = readme_file.read()

#with open("tinode_grpc/GIT_VERSION", "r") as version_file:
# git_version = version_file.read().strip()
git_version = resource_string(__name__, 'tinode_grpc/GIT_VERSION').decode('ascii')
with open("tinode_grpc/GIT_VERSION", "r") as version_file:
git_version = version_file.read().strip()
# git_version = resource_string(__name__, 'tinode_grpc/GIT_VERSION').decode('ascii')

setuptools.setup(
name="tinode_grpc",
Expand All @@ -19,7 +19,7 @@
long_description_content_type="text/markdown",
url="https://github.com/tinode/chat",
packages=setuptools.find_packages(),
install_requires=['protobuf>=3.6.1', 'grpcio>=1.15.0'],
install_requires=['protobuf>=3.6.1', 'grpcio>=1.19.0'],
license="Apache 2.0",
keywords="chat messaging messenger im tinode",
package_data={
Expand Down
2 changes: 1 addition & 1 deletion server/hdl_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func serveGrpc(addr string, tlsConf *tls.Config) (*grpc.Server, error) {
}
srv := grpc.NewServer(opts...)
pbx.RegisterNodeServer(srv, &grpcNodeServer{})
log.Printf("gRPC%s server is registered at [%s]", secure, addr)
log.Printf("gRPC/%s%s server is registered at [%s]", grpc.Version, secure, addr)

go func() {
if err := srv.Serve(lis); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tn-cli/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
futures>=3.2.0; python_version<'3'
grpcio>=1.18.0
grpcio>=1.19.0
Pillow>=5.4.1
requests>=2.21.0
tinode-grpc>=0.15.11
tinode-grpc>=0.15.13
80 changes: 44 additions & 36 deletions tn-cli/tn-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
# This is needed for gRPC SSL to work correctly.
os.environ["GRPC_SSL_CIPHER_SUITES"] = "HIGH+ECDSA"

# Enable the following variables for debugging.
# os.environ["GRPC_TRACE"] = "all"
# os.environ["GRPC_VERBOSITY"] = "INFO"

# Dictionary wich contains lambdas to be executed when server {ctrl} response is received.
OnCompletion = {}

Expand Down Expand Up @@ -313,7 +317,7 @@ def stdin(InputQueue):
def hiMsg(id):
OnCompletion[str(id)] = lambda params: print_server_params(params)
return pb.ClientMsg(hi=pb.ClientHi(id=str(id), user_agent=APP_NAME + "/" + APP_VERSION + " (" +
platform.system() + "/" + platform.release() + "); gRPC-python/" + LIB_VERSION,
platform.system() + "/" + platform.release() + "); gRPC-python/" + LIB_VERSION + "-" + GRPC_VERSION,
ver=LIB_VERSION, lang="EN"))

# {acc}
Expand Down Expand Up @@ -711,7 +715,6 @@ def parse_input(cmd):
# protobuf messages for remote commands.
def serialize_cmd(string, id, args):
"""Take string read from the command line, convert in into a protobuf message"""
cmd = {}
messages = {
"acc": accMsg,
"login": loginMsg,
Expand Down Expand Up @@ -796,43 +799,48 @@ def gen_message(scheme, secret, args):
print_prompt = True

while True:
if not WaitingFor and not InputQueue.empty():
id += 1
inp = InputQueue.get()

if inp == 'exit' or inp == 'quit' or inp == '.exit' or inp == '.quit':
return
try:
if not WaitingFor and not InputQueue.empty():
id += 1
inp = InputQueue.get()

if inp == 'exit' or inp == 'quit' or inp == '.exit' or inp == '.quit':
return

pbMsg, cmd = serialize_cmd(inp, id, args)
print_prompt = IsInteractive
if pbMsg != None:
if not IsInteractive:
sys.stdout.write("=> " + inp + "\n")
sys.stdout.flush()

if cmd.synchronous:
cmd.await_ts = time.time()
cmd.await_id = str(id)
WaitingFor = cmd

if not hasattr(cmd, 'no_yield'):
yield pbMsg

elif not OutputQueue.empty():
sys.stdout.write("\r<= "+OutputQueue.get())
sys.stdout.flush()
print_prompt = IsInteractive

pbMsg, cmd = serialize_cmd(inp, id, args)
print_prompt = IsInteractive
if pbMsg != None:
if not IsInteractive:
sys.stdout.write("=> " + inp + "\n")
else:
if print_prompt:
sys.stdout.write("tn> ")
sys.stdout.flush()
print_prompt = False
if WaitingFor:
if time.time() - WaitingFor.await_ts > AWAIT_TIMEOUT:
stdoutln("Timeout while waiting for '{0}' response".format(WaitingFor.cmd))
WaitingFor = None

if cmd.synchronous:
cmd.await_ts = time.time()
cmd.await_id = str(id)
WaitingFor = cmd
time.sleep(0.1)

if not cmd.no_yield:
yield pbMsg

elif not OutputQueue.empty():
sys.stdout.write("\r<= "+OutputQueue.get())
sys.stdout.flush()
print_prompt = IsInteractive

else:
if print_prompt:
sys.stdout.write("tn> ")
sys.stdout.flush()
print_prompt = False
if WaitingFor:
if time.time() - WaitingFor.await_ts > AWAIT_TIMEOUT:
stdoutln("Timeout while waiting for '{0}' response".format(WaitingFor.cmd))
WaitingFor = None
time.sleep(0.1)
except Exception as err:
stdoutln("Exception in generator: {0}".format(err))


# Handle {ctrl} server response
Expand Down Expand Up @@ -924,7 +932,7 @@ def run(args, schema, secret):
stdoutln("\rMessage type not handled" + str(msg))

except grpc.RpcError as err:
print(err)
# print(err)
printerr("gRPC failed with {0}: {1}".format(err.code(), err.details()))
except Exception as ex:
printerr("Request failed: {0}".format(ex))
Expand Down

0 comments on commit dfe1b0f

Please sign in to comment.