0

I am trying to get started with Python + gRCP and so I checked out their repository as mentioned in the gRPC guide (https://grpc.io/docs/quickstart/python/).

Now I could execute the Hello World-Script (Client + Server), and so I tried to modify it. To ensure I did not missconfigure anything I just extended the Hello World-function (that use to work out before). I added the following lines:

import time

def SayHello(self, request, context):
        currentTime = time.clock_gettime(time.CLOCK_REALTIME)
        return helloworld_pb2.HelloReply(message='Time is, %s!' % currentTime)

Now what I inmagined it would do is to simply pass the currentTime-object back in this message I am returning upon that function is called - yet, what happens is the following error:

ERROR:grpc._server:Exception calling application: 'module' object has no attribute 'clock_gettime' Traceback (most recent call last): File "/home/user/.local/lib/python2.7/site-packages/grpc/_server.py", line 435, in _call_behavior response_or_iterator = behavior(argument, context) File "greeter_server.py", line 29, in SayHello currentTime = time.clock_gettime(time.CLOCK_REALTIME) AttributeError: 'module' object has no attribute 'clock_gettime'

I tried to Google around and I found that this might occur if you have a file named time in the same directory (so Python confuses the file in the current directory with the time-file. Yet there is no such file and he seems to find the correct time-file (since I can see the documentation when I hover the import and the function). What did I do wrong here?

The "full" Server Code (up to the serve() function):

from concurrent import futures
import logging
import time

import grpc

import helloworld_pb2
import helloworld_pb2_grpc


class Greeter(helloworld_pb2_grpc.GreeterServicer):

    def SayHello(self, request, context):
        currentTime = time.clock_gettime(time.CLOCK_REALTIME)
        return helloworld_pb2.HelloReply(message='Time is, %s!' % currentTime)

Edit: I am using Ubuntu if that is important.

Rüdiger
  • 893
  • 5
  • 27
  • 56

1 Answers1

1

time.clock_gettime is a 3.3+ API and you are using 2.7.

Lidi Zheng
  • 1,801
  • 8
  • 13