Пример #1
0
    def __init__(self, space, image=None, trace_important=False,
                 trace=False, evented=True, interrupts=True):
        # === Initialize immutable variables
        self.space = space
        self.image = image
        if image:
            self.startup_time = image.startup_time
        else:
            self.startup_time = constants.CompileTime
        self.evented = evented
        self.interrupts = interrupts
        self.trace_important = trace_important
        try:
            self.interrupt_counter_size = int(os.environ["SPY_ICS"])
        except KeyError:
            self.interrupt_counter_size = constants.INTERRUPT_COUNTER_SIZE
        self.last_check = self.time_now()
        self.trace = trace

        # === Initialize mutable variables
        self.interrupt_check_counter = self.interrupt_counter_size
        self.next_wakeup_tick = 0
        self.stack_depth = 0
        self.process_switch_count = 0
        self.forced_interrupt_checks_count = 0
        self.stack_overflow_count = 0

        if not objectmodel.we_are_translated():
            if USE_SIGUSR1:
                rsignal.pypysig_setflag(rsignal.SIGUSR1)
Пример #2
0
    def __init__(self, space, image=None, trace_important=False,
                 trace=False, evented=True, interrupts=True):
        # === Initialize immutable variables
        self.space = space
        self.image = image
        if image:
            self.startup_time = image.startup_time
        else:
            self.startup_time = constants.CompileTime
        self.evented = evented
        self.interrupts = interrupts
        self.trace_important = trace_important
        try:
            self.interrupt_counter_size = int(os.environ["SPY_ICS"])
        except KeyError:
            self.interrupt_counter_size = constants.INTERRUPT_COUNTER_SIZE
        self.trace = trace

        # === Initialize mutable variables
        self.interrupt_check_counter = self.interrupt_counter_size
        self.next_wakeup_tick = 0
        self.trace_proxy = objspace.ConstantFlag()
        self.stack_depth = 0
        self.process_switch_count = 0
        self.forced_interrupt_checks_count = 0
        self.stack_overflow_count = 0

        if not objectmodel.we_are_translated():
            if USE_SIGUSR1:
                rsignal.pypysig_setflag(rsignal.SIGUSR1)
Пример #3
0
 def does_stuff():
     rsignal.pypysig_setflag(signal.SIGUSR1)
     os.kill(os.getpid(), signal.SIGUSR1)
     rsignal.pypysig_ignore(signal.SIGUSR1)
     while True:
         n = rsignal.pypysig_poll()
         if n < 0 or n == signal.SIGUSR1:
             break
     return n
Пример #4
0
 def does_stuff():
     rsignal.pypysig_setflag(signal.SIGUSR1)
     os.kill(os.getpid(), signal.SIGUSR1)
     rsignal.pypysig_ignore(signal.SIGUSR1)
     while True:
         n = rsignal.pypysig_poll()
         if n < 0 or n == signal.SIGUSR1:
             break
     return n
Пример #5
0
 def does_stuff():
     os.setpgid(0, 0)  # become its own separated process group
     rsignal.pypysig_setflag(signal.SIGUSR1)
     os.killpg(os.getpgrp(), signal.SIGUSR1)
     rsignal.pypysig_ignore(signal.SIGUSR1)
     while True:
         n = rsignal.pypysig_poll()
         if n < 0 or n == signal.SIGUSR1:
             break
     return n
Пример #6
0
 def does_stuff():
     os.setpgid(0, 0)     # become its own separated process group
     rsignal.pypysig_setflag(signal.SIGUSR1)
     os.killpg(os.getpgrp(), signal.SIGUSR1)
     rsignal.pypysig_ignore(signal.SIGUSR1)
     while True:
         n = rsignal.pypysig_poll()
         if n < 0 or n == signal.SIGUSR1:
             break
     return n
Пример #7
0
 def fn():
     rd, wr = os.pipe()
     rsignal.pypysig_set_wakeup_fd(wr, False)
     for i in range(3):
         rsignal.pypysig_setflag(rsignal.SIGUSR1)
         os.kill(os.getpid(), rsignal.SIGUSR1)
         check(rsignal.SIGUSR1)
         check(-1)
         check(-1)
     x = os.read(rd, 10)
     assert x == chr(rsignal.SIGUSR1) * 3
     #
     rsignal.pypysig_set_wakeup_fd(rd, False)  # can't write there
     os.kill(os.getpid(), rsignal.SIGUSR1)
Пример #8
0
 def f():
     l = allocate_lock()
     l.acquire(True)
     #
     rsignal.pypysig_setflag(rsignal.SIGALRM)
     rsignal.c_alarm(1)
     #
     t1 = time.time()
     ok = l.acquire_timed(2500000)
     t2 = time.time()
     delay = t2 - t1
     if ok == 0:        # RPY_LOCK_FAILURE
         return -delay
     elif ok == 2:      # RPY_LOCK_INTR
         return delay
     else:              # RPY_LOCK_ACQUIRED
         return 0.0
Пример #9
0
def test_simple():
    import os
    check(-1)
    check(-1)
    for i in range(3):
        rsignal.pypysig_setflag(rsignal.SIGUSR1)
        os.kill(os.getpid(), rsignal.SIGUSR1)
        check(rsignal.SIGUSR1)
        check(-1)
        check(-1)

    rsignal.pypysig_ignore(rsignal.SIGUSR1)
    os.kill(os.getpid(), rsignal.SIGUSR1)
    check(-1)
    check(-1)

    rsignal.pypysig_default(rsignal.SIGUSR1)
    check(-1)
Пример #10
0
def test_raise():
    import os
    check(-1)
    check(-1)
    for i in range(3):
        rsignal.pypysig_setflag(rsignal.SIGUSR1)
        rsignal.c_raise(rsignal.SIGUSR1)
        check(rsignal.SIGUSR1)
        check(-1)
        check(-1)

    rsignal.pypysig_ignore(rsignal.SIGUSR1)
    rsignal.c_raise(rsignal.SIGUSR1)
    check(-1)
    check(-1)

    rsignal.pypysig_default(rsignal.SIGUSR1)
    check(-1)
Пример #11
0
def test_simple():
    import os
    check(-1)
    check(-1)
    for i in range(3):
        rsignal.pypysig_setflag(rsignal.SIGUSR1)
        os.kill(os.getpid(), rsignal.SIGUSR1)
        check(rsignal.SIGUSR1)
        check(-1)
        check(-1)

    rsignal.pypysig_ignore(rsignal.SIGUSR1)
    os.kill(os.getpid(), rsignal.SIGUSR1)
    check(-1)
    check(-1)

    rsignal.pypysig_default(rsignal.SIGUSR1)
    check(-1)
Пример #12
0
def entry_point(argv):
    rsignal.pypysig_setflag(rsignal.SIGINT)
    rsocket.rsocket_startup()

    constructor = bytecode.constructor.BytecodeConstructor()

    if len(argv) < 3:
        print_usage(argv[0])
        return 1

    trace_fd = None
    mode = argv[1]
    if mode == 'exec':
        program = argv[2]
        argv = argv[2:]
        sys_caller = sys_calls.Perform(program)
    elif mode == 'trace' and len(argv) >= 4:
        program = argv[3]
        trace_fd = open(argv[2], 'w')
        argv = argv[3:]
        sys_caller = sys_calls.TraceProxy(sys_calls.Perform(program), trace_fd)
    elif mode == 'replay' and len(argv) >= 4:
        program = argv[3]
        argv = argv[3:]
        trace_fd = open(argv[2], 'r')
        sys_caller = sys_calls.Replay(trace_fd)
    else:
        print_usage(argv[0])
        return 1

    with open(program, 'r') as fd:
        bytecode.read.read_bytecode(fd, constructor)

    arguments = [operators.list.DList([data.ByteString(arg) for arg in argv])]

    try:
        ex = executor.execute(sys_caller, constructor.get_program(), arguments)
    finally:
        if trace_fd:
            trace_fd.close()

    return 0
Пример #13
0
 def init_signals(self):
     if self.initialized:
         return
     self.initialized = True
     rsignal.pypysig_setflag(signal.SIGINT)
Пример #14
0
 def init_signals(self):
     if self.initialized:
         return
     self.initialized = True
     rsignal.pypysig_setflag(signal.SIGINT)