Python time.h() Examples

The following are code examples for showing how to use time.h(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: D-VAE   Author: muhanzhang   File: blas.py    MIT License 5 votes vote down vote up
def c_headers(self):
        # std.cout doesn't require the '%' symbol to print stuff...
        # so it works much better with python's string-substitution stuff.
        return ['<iostream>', '<time.h>', '<sys/time.h>'] 
Example 2
Project: poker   Author: surgebiswas   File: blas.py    MIT License 5 votes vote down vote up
def c_headers(self):
        # std.cout doesn't require the '%' symbol to print stuff...
        # so it works much better with python's string-substitution stuff.
        return ['<iostream>', '<time.h>', '<sys/time.h>'] 
Example 3
Project: attention-lvcsr   Author: rizar   File: blas.py    MIT License 5 votes vote down vote up
def c_headers(self):
        # std.cout doesn't require the '%' symbol to print stuff...
        # so it works much better with python's string-substitution stuff.
        return ['<iostream>', '<time.h>', '<sys/time.h>'] 
Example 4
Project: PyVM   Author: ForceBru   File: kernel_sys.py    MIT License 5 votes vote down vote up
def sys_clock_gettime(kernel: Kernel, clk_id: Uint, tp_addr: Uint):
    """
    int clock_gettime(clockid_t clk_id, struct timespec *tp);

    The functions clock_gettime() and clock_settime() retrieve and set
   the time of the specified clock clk_id.

   The res and tp arguments are timespec structures, as specified in
   <time.h>:

    struct timespec {
        time_t   tv_sec;        /* seconds */
        long     tv_nsec;       /* nanoseconds */
    };
    """

    struct_timespec = struct.Struct('<II')

    import time

    time_nanoseconds = int(time.time() * 1_000_000_000)  # Python 3.6 compatibility
    sec, nsec = time_nanoseconds // 1_000_000_000, time_nanoseconds % 1_000_000_000

    kernel.cpu.mem.set_bytes(tp_addr, struct_timespec.size, struct_timespec.pack(sec, nsec))

    return 0 
Example 5
Project: kivy-doc-ja   Author: pyKy   File: clock.py    MIT License 5 votes vote down vote up
def _libc_clock_gettime_wrapper():
                from os import strerror

                class struct_tv(ctypes.Structure):
                    _fields_ = [('tv_sec', ctypes.c_long),
                                ('tv_usec', ctypes.c_long)]

                _clock_gettime = _libc.clock_gettime
                _clock_gettime.argtypes = [ctypes.c_long,
                                           ctypes.POINTER(struct_tv)]

                if 'linux' in platform:
                    _clockid = 4  # CLOCK_MONOTONIC_RAW (Linux specific)
                elif 'freebsd' in platform:
                    # clockid constants from sys/time.h
                    # _clockid = 4 # CLOCK_MONOTONIC (FreeBSD specific)
                    # 11: CLOCK_MONOTONIC_PRECISE (FreeBSD known OK for 10.2)
                    _clockid = 11
                    # _clockid = 12
                    # 12: CLOCK_MONOTONIC_FAST (FreeBSD specific)
                    Logger.debug('clock.py: {{{:s}}} clock ID {:d}'.format(
                        platform, _clockid))
                else:
                    _clockid = 1  # CLOCK_MONOTONIC

                tv = struct_tv()

                def _time():
                    if _clock_gettime(ctypes.c_long(_clockid),
                                      ctypes.pointer(tv)) != 0:
                        _ernno = ctypes.get_errno()
                        raise OSError(_ernno, strerror(_ernno))
                    return tv.tv_sec + (tv.tv_usec * 0.000000001)

                return _time 
Example 6
Project: twinnet-asr   Author: dmitriy-serdyuk   File: blas.py    MIT License 5 votes vote down vote up
def c_headers(self):
        # std.cout doesn't require the '%' symbol to print stuff...
        # so it works much better with python's string-substitution stuff.
        return ['<iostream>', '<time.h>', '<sys/time.h>'] 
Example 7
Project: dependency-parser   Author: mzapotoczny   File: blas.py    MIT License 5 votes vote down vote up
def c_headers(self):
        # std.cout doesn't require the '%' symbol to print stuff...
        # so it works much better with python's string-substitution stuff.
        return ['<iostream>', '<time.h>', '<sys/time.h>'] 
Example 8
Project: eden   Author: facebookexperimental   File: setup.py    GNU General Public License v2.0 4 votes vote down vote up
def build_extensions(self):
        fetchbuilddeps(self.distribution).run()

        re2path = "build/re2-2018-04-01"
        self.extensions.append(
            Extension(
                "edenscmnative._re2",
                sources=[
                    "edenscm/mercurial/thirdparty/pyre2/_re2.cc",
                    os.path.join(re2path, "re2/bitstate.cc"),
                    os.path.join(re2path, "re2/compile.cc"),
                    os.path.join(re2path, "re2/dfa.cc"),
                    os.path.join(re2path, "re2/filtered_re2.cc"),
                    os.path.join(re2path, "re2/mimics_pcre.cc"),
                    os.path.join(re2path, "re2/nfa.cc"),
                    os.path.join(re2path, "re2/onepass.cc"),
                    os.path.join(re2path, "re2/parse.cc"),
                    os.path.join(re2path, "re2/perl_groups.cc"),
                    os.path.join(re2path, "re2/prefilter.cc"),
                    os.path.join(re2path, "re2/prefilter_tree.cc"),
                    os.path.join(re2path, "re2/prog.cc"),
                    os.path.join(re2path, "re2/re2.cc"),
                    os.path.join(re2path, "re2/regexp.cc"),
                    os.path.join(re2path, "re2/set.cc"),
                    os.path.join(re2path, "re2/simplify.cc"),
                    os.path.join(re2path, "re2/stringpiece.cc"),
                    os.path.join(re2path, "re2/tostring.cc"),
                    os.path.join(re2path, "re2/unicode_casefold.cc"),
                    os.path.join(re2path, "re2/unicode_groups.cc"),
                    os.path.join(re2path, "util/rune.cc"),
                    os.path.join(re2path, "util/strutil.cc"),
                ],
                include_dirs=[re2path] + include_dirs,
                depends=common_depends
                + [
                    os.path.join(re2path, "re2/bitmap256.h"),
                    os.path.join(re2path, "re2/filtered_re2.h"),
                    os.path.join(re2path, "re2/prefilter.h"),
                    os.path.join(re2path, "re2/prefilter_tree.h"),
                    os.path.join(re2path, "re2/prog.h"),
                    os.path.join(re2path, "re2/re2.h"),
                    os.path.join(re2path, "re2/regexp.h"),
                    os.path.join(re2path, "re2/set.h"),
                    os.path.join(re2path, "re2/stringpiece.h"),
                    os.path.join(re2path, "re2/unicode_casefold.h"),
                    os.path.join(re2path, "re2/unicode_groups.h"),
                    os.path.join(re2path, "re2/walker-inl.h"),
                    os.path.join(re2path, "util/logging.h"),
                    os.path.join(re2path, "util/mix.h"),
                    os.path.join(re2path, "util/mutex.h"),
                    os.path.join(re2path, "util/sparse_array.h"),
                    os.path.join(re2path, "util/sparse_set.h"),
                    os.path.join(re2path, "util/strutil.h"),
                    os.path.join(re2path, "util/utf.h"),
                    os.path.join(re2path, "util/util.h"),
                ],
                extra_compile_args=filter(None, [STDCPP11, PRODUCEDEBUGSYMBOLS]),
            )
        )

        return build_ext.build_extensions(self)