Mantid
Loading...
Searching...
No Matches
PythonStdoutChannel.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
8// local includes
10
11// 3rd-party includes
14#include <boost/format.hpp>
15#include <boost/iostreams/categories.hpp> // sink_tag
16#include <boost/iostreams/stream.hpp>
17
18#include <iostream> // streamsize
19
20namespace { // anonymous namespace
21
22class PyStdoutSink {
23public:
24 using char_type = char;
25 using category = boost::iostreams::sink_tag;
26
27 std::streamsize write(const char *s, std::streamsize n) {
29 // PySys_WriteStdout truncates to 1000 chars
30 static const std::streamsize MAXSIZE = 1000;
31
32 std::streamsize written = std::min(n, MAXSIZE);
33 PySys_WriteStdout((boost::format("%%.%1%s") % written).str().c_str(), s);
34
35 return written;
36 } // release the GIL
37};
38
39// wrapper of that sink to be a stream
40PyStdoutSink pyStdoutSinkInstance = PyStdoutSink(); // needs to be initialized separately
41boost::iostreams::stream<PyStdoutSink> PyStdoutStream(pyStdoutSinkInstance);
42
43} // anonymous namespace
44
45namespace Poco {
46PythonStdoutChannel::PythonStdoutChannel() : ConsoleChannel(PyStdoutStream) {}
47} // namespace Poco
Defines a structure for acquiring/releasing the Python GIL using the RAII pattern.
PythonStdoutChannel()
Constructor for PythonStdoutChannel.
MANTID_DATAHANDLING_DLL void write(H5::Group &group, const std::string &name, const std::string &value)
Definition: Algorithm.h:30