-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1290dc
commit ca0b1fd
Showing
4 changed files
with
96 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and * | ||
* Wolf Vollprecht * | ||
* Copyright (c) 2018, QuantStack | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
#ifndef XPYT_HOOK_HPP | ||
#define XPYT_HOOK_HPP | ||
|
||
#include "xeus-python/xeus_python_config.hpp" | ||
#include "xeus-zmq/xhook_base.hpp" | ||
|
||
#include "pybind11/embed.h" | ||
#include "pybind11/pybind11.h" | ||
|
||
namespace py = pybind11; | ||
|
||
namespace xpyt | ||
{ | ||
XEUS_PYTHON_API | ||
class hook : public xeus::xhook_base | ||
{ | ||
public: | ||
hook() = default; | ||
|
||
void pre_hook() override; | ||
void post_hook() override; | ||
void run(std::shared_ptr<uvw::loop> loop) override; | ||
|
||
private: | ||
py::gil_scoped_acquire* p_acquire{ nullptr}; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay, and * | ||
* Wolf Vollprecht * | ||
* Copyright (c) 2018, QuantStack | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
#ifndef UVW_AS_LIB | ||
#define UVW_AS_LIB | ||
#include <uvw.hpp> | ||
#endif | ||
|
||
#include <iostream> // REMOVE | ||
|
||
#include "xeus-python/xhook.hpp" | ||
|
||
#include "pybind11/embed.h" | ||
#include "pybind11/pybind11.h" | ||
|
||
namespace py = pybind11; | ||
|
||
namespace xpyt | ||
{ | ||
void hook::pre_hook() | ||
{ | ||
if (!p_acquire) | ||
{ | ||
std::cout << "Acquiring GIL" << std::endl; | ||
p_acquire = new py::gil_scoped_acquire(); | ||
} | ||
} | ||
|
||
void hook::post_hook() | ||
{ | ||
delete p_acquire; | ||
p_acquire = nullptr; | ||
std::cout << "Deleted GIL" << std::endl; | ||
} | ||
|
||
void hook::run(std::shared_ptr<uvw::loop> /* loop */) | ||
{ | ||
std::cout << "Running loop" << std::endl; | ||
py::gil_scoped_acquire acquire; | ||
py::module asyncio = py::module::import("asyncio"); | ||
py::object loop = asyncio.attr("get_event_loop")(); | ||
loop.attr("run_forever")(); | ||
} | ||
} |