コード例 #1
0
ファイル: interrupt.c プロジェクト: antworteffekt/sage
/* Handler for SIGINT */
void sage_interrupt_handler(int sig)
{
#if ENABLE_DEBUG_INTERRUPT
    fprintf(stderr, "\n*** SIGINT *** %s sig_on\n", (_signals.sig_on_count > 0) ? "inside" : "outside");
    print_backtrace();
#endif

    if (_signals.sig_on_count > 0)
    {
        if (_signals.block_sigint)
        {
            /* SIGINT is blocked, so simply set _signals.interrupt_received. */
            _signals.interrupt_received = 1;
            return;
        }

        /* Raise KeyboardInterrupt */
        PyErr_SetNone(PyExc_KeyboardInterrupt);

        /* Jump back to sig_on() (the first one if there is a stack) */
        reset_CPU();
        siglongjmp(_signals.env, sig);
    }
    else
    {
        /* Set an internal Python flag that an interrupt has been
         * raised.  This will not immediately raise an exception, only
         * on the next call of PyErr_CheckSignals().  We cannot simply
         * raise an exception here because of Python's "global
         * interpreter lock" -- Jeroen Demeyer */
        PyErr_SetInterrupt();
        _signals.interrupt_received = 1;
    }
}
コード例 #2
0
static PyObject *
thread_PyThread_interrupt_main(PyObject * self)
{
	PyErr_SetInterrupt();
	Py_INCREF(Py_None);
	return Py_None;
}
コード例 #3
0
ファイル: pythonengine.cpp プロジェクト: deniq/agros2d
int scriptQuit(void *)
{
    PyErr_SetString(PyExc_SystemError, "Script interrupted.");
    PyErr_SetInterrupt();

    return 0;
}
コード例 #4
0
ファイル: server.c プロジェクト: andrewleech/bjoern
static void
ev_signal_on_sigint(struct ev_loop* mainloop, ev_signal* watcher, const int events)
{
    /* Clean up and shut down this thread.
     * (Shuts down the Python interpreter if this is the main thread) */
    ev_unloop(mainloop, EVUNLOOP_ALL);
    PyErr_SetInterrupt();
}
コード例 #5
0
void
pbs_python_set_interrupt(void)
{

#ifdef PYTHON
	PyErr_SetInterrupt();
#endif
}
コード例 #6
0
ファイル: downloader-py.c プロジェクト: j-mracek/librepo
PyObject *
py_download_url(G_GNUC_UNUSED PyObject *self, PyObject *args)
{
    gboolean ret;
    PyObject *py_handle;
    LrHandle *handle = NULL;
    char *url;
    int fd;
    GError *tmp_err = NULL;
    PyThreadState *state = NULL;

    if (!PyArg_ParseTuple(args, "Osi:download_url",
                          &py_handle, &url, &fd))
        return NULL;

    Py_XINCREF(py_handle);

    if (HandleObject_Check(py_handle)) {
        handle = Handle_FromPyObject(py_handle);
    } else if (py_handle != Py_None) {
        PyErr_SetString(PyExc_TypeError, "Only Handle or None is supported");
        return NULL;
    }

    // XXX: GIL Hack
    int hack_rc = gil_logger_hack_begin(&state);
    if (hack_rc == GIL_HACK_ERROR)
        return NULL;

    BeginAllowThreads(&state);
    ret = lr_download_url(handle, url, fd, &tmp_err);
    EndAllowThreads(&state);

    // XXX: GIL Hack
    if (!gil_logger_hack_end(hack_rc))
        return NULL;

    assert((ret && !tmp_err) || (!ret && tmp_err));

    if (ret)
        Py_RETURN_NONE; // All fine - Return None

    // Error occurred
    if (PyErr_Occurred()) {
        // Python exception occurred (in a python callback probably)
        return NULL;
    } else if(tmp_err->code == LRE_INTERRUPTED) {
        // Interrupted by Ctr+C
        g_error_free(tmp_err);
        PyErr_SetInterrupt();
        PyErr_CheckSignals();
        return NULL;
    } else {
        // Return exception created from GError
        RETURN_ERROR(&tmp_err, -1, NULL);
    }
}
コード例 #7
0
void ProcessShellMessage( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	UINT cmdId = 0;
	switch (lParam) {
        case WM_LBUTTONUP:
			cmdId = ID_SHELL_ACTIVATE;
			break;
        case WM_RBUTTONUP: 
		{

			CMenu menu;
			menu.LoadMenu(MAKEINTRESOURCE(IDR_SHELLTRAY));
//			HMENU hMenu = AfxGetApp()->LoadMenu(MAKEINTRESOURCE(IDR_SHELLTRAY));
//			HWND hWndMain = AfxGetMainWnd()->GetSafeHwnd();
			HMENU hMenuTrackPopup = *menu.GetSubMenu (0); // convert to a HMENU
			POINT pt;
			GetCursorPos(&pt);
			// This is required when using a notify icon -- see KB article 
			// PRB: Menus for Notification Icons Don't Work Correctly 
			SetForegroundWindow (hWnd);
			SetMenuDefaultItem(hMenuTrackPopup, 0, MF_BYPOSITION);
			cmdId = TrackPopupMenu(hMenuTrackPopup, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RETURNCMD | TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL);

			// This is required when using a notify icon -- see KB article 
			// PRB: Menus for Notification Icons Don't Work Correctly 
			::PostMessage (hWnd, WM_USER, 0, 0);
			break;
		}
		break;
	}

	switch (cmdId) {
		case ID_SHELL_ACTIVATE: 
		{
			HWND hwndMain = AfxGetMainWnd()->GetSafeHwnd();
			BOOL ok = (hwndMain != NULL);
			if (ok)
				::SetForegroundWindow(hwndMain);
			if (ok) {
				WINDOWPLACEMENT wp;
				wp.length = sizeof(wp);
				ok = ::GetWindowPlacement(hwndMain, &wp);
				if (ok && wp.showCmd==SW_SHOWMINIMIZED)
					::ShowWindow(hwndMain, SW_RESTORE);
			}
			break;
		}
		case ID_SHELL_BREAK:
			// set a flag to tell the process to break;
			PyErr_SetInterrupt();
			break;
		default:
			break;
	}
}
コード例 #8
0
ファイル: io.c プロジェクト: tsavola/cio
static PyObject *py_cio_io(enum cio_io_type type, PyObject *args, const char *format)
{
	int fd;
	Py_buffer buf;
	Py_ssize_t size;
	int flags;
	ssize_t len;
	int err;

	if (!PyArg_ParseTuple(args, format, &fd, &buf, &size, &flags))
		return NULL;

	py_cio_thread_save();

	if (size > buf.len)
		size = buf.len;

	switch (type) {
	case CIO_IO_READ:
		len = cio_read(fd, buf.buf, size);
		break;

	case CIO_IO_WRITE:
		len = cio_write(fd, buf.buf, size);
		break;

	case CIO_IO_RECV:
		len = cio_recv(fd, buf.buf, size, flags);
		break;

	case CIO_IO_SEND:
		len = cio_send(fd, buf.buf, size, flags);
		break;
	}

	err = errno;

	if (len < 0 && errno == EINTR)
		PyErr_SetInterrupt();

	py_cio_thread_restore();

	PyBuffer_Release(&buf);

	if (len < 0) {
		errno = err;
		return PyErr_SetFromErrno(PyExc_IOError);
	}

	return PyLong_FromLong(len);
}
コード例 #9
0
static int python_watch_dog( void * )
{
    //
    // See if there is any input activity to process
    //
    theActiveView->k_check_for_input();

    if( check_for_interrupt_key() )
    {
        // check the interrupt state
        interrupt_key_struck = 0;
        // interrupt Python
        PyErr_SetInterrupt();
    }

    // signal we are out of the queue
    SetEvent( h_watch_dog_queued_event );

    return 0;
}
コード例 #10
0
ファイル: interrupt.c プロジェクト: chos9/sage
/* Handler for SIGHUP, SIGINT */
void sage_interrupt_handler(int sig)
{
#if ENABLE_DEBUG_INTERRUPT
    if (sage_interrupt_debug_level >= 1) {
        fprintf(stderr, "\n*** SIG %i *** %s sig_on\n", sig, (_signals.sig_on_count > 0) ? "inside" : "outside");
        if (sage_interrupt_debug_level >= 3) print_backtrace();
        fflush(stderr);
        /* Store time of this signal, unless there is already a
         * pending signal. */
        if (!_signals.interrupt_received) gettimeofday(&sigtime, NULL);
    }
#endif

    if (_signals.sig_on_count > 0)
    {
        if (!_signals.block_sigint)
        {
            /* Actually raise an exception so Python can see it */
            sig_raise_exception(sig);

            /* Jump back to sig_on() (the first one if there is a stack) */
            reset_CPU();
            siglongjmp(_signals.env, sig);
        }
    }
    else
    {
        /* Set the Python interrupt indicator, which will cause the
         * Python-level interrupt handler in sage/ext/c_lib.pyx to be
         * called. */
        PyErr_SetInterrupt();
    }

    /* If we are here, we cannot handle the interrupt immediately, so
     * we store the signal number for later use.  But make sure we
     * don't overwrite a SIGHUP or SIGTERM which we already received. */
    if (_signals.interrupt_received != SIGHUP && _signals.interrupt_received != SIGTERM)
        _signals.interrupt_received = sig;
}
コード例 #11
0
ファイル: pycore.c プロジェクト: irssi-import/irssi-python
/* why doesn't this get called? */
static void intr_catch(int sig)
{
    printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "got sig %d", sig);
    PyErr_SetInterrupt();
}
コード例 #12
0
ファイル: python.c プロジェクト: SparkleLin/core_analyzer
void
set_quit_flag (void)
{
  PyErr_SetInterrupt ();
}
コード例 #13
0
ファイル: server.c プロジェクト: crudbug/bjoern
static void
pyerr_set_interrupt(struct ev_loop* mainloop, struct ev_cleanup* watcher, const int events)
{
  PyErr_SetInterrupt();
  free(watcher);
}