Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add python 3.8 compatibility #1258

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion autobahn/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,17 @@ def generate_serial_number():
return generate_token(char_groups=6, chars_per_group=4, chars=DEFAULT_TOKEN_CHARS, sep=u'-', lower_case=False)


def _get_clock_impl():
if sys.version_info >= (3, 3):
return time.process_time
else:
return time.clock


def get_clock():
return _get_clock_impl()()


# Select the most precise walltime measurement function available
# on the platform
#
Expand All @@ -463,7 +474,7 @@ def generate_serial_number():
# first call to this function, as a floating point number, based on the
# Win32 function QueryPerformanceCounter(). The resolution is typically
# better than one microsecond
_rtime = time.clock
_rtime = _get_clock_impl()
_ = _rtime() # this starts wallclock
else:
# On Unix-like platforms, this used the first available from this list:
Expand Down
8 changes: 5 additions & 3 deletions examples/asyncio/wamp/rpc/slowsquare/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
###############################################################################

from os import environ
import sys
import time

import asyncio
from functools import partial

from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
from autobahn.util import get_clock


class Component(ApplicationSession):
Expand All @@ -42,14 +44,14 @@ async def onJoin(self, details):

def got(started, msg, f):
res = f.result()
duration = 1000. * (time.clock() - started)
duration = 1000. * (get_clock() - started)
print("{}: {} in {}".format(msg, res, duration))

t1 = time.clock()
t1 = get_clock()
d1 = self.call(u'com.math.slowsquare', 3, 2)
d1.add_done_callback(partial(got, t1, "Slow Square"))

t2 = time.clock()
t2 = get_clock()
d2 = self.call(u'com.math.square', 3)
d2.add_done_callback(partial(got, t2, "Quick Square"))

Expand Down
8 changes: 5 additions & 3 deletions examples/twisted/wamp/rpc/slowsquare/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@

import time
from os import environ
import sys

from twisted.internet import reactor
from twisted.internet.defer import DeferredList

from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
from autobahn.util import get_clock


class Component(ApplicationSession):
Expand All @@ -42,14 +44,14 @@ def onJoin(self, details):
print("session attached")

def got(res, started, msg):
duration = 1000. * (time.clock() - started)
duration = 1000. * (get_clock() - started)
print("{}: {} in {}".format(msg, res, duration))

t1 = time.clock()
t1 = get_clock()
d1 = self.call(u'com.math.slowsquare', 3)
d1.addCallback(got, t1, "Slow Square")

t2 = time.clock()
t2 = get_clock()
d2 = self.call(u'com.math.square', 3)
d2.addCallback(got, t2, "Quick Square")

Expand Down