Python os.mkfifo() Examples
The following are 30
code examples of os.mkfifo().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: test_file_subcommand_fifo.py From sqlitebiter with MIT License | 7 votes |
def test_smoke_one_file(self): db_path = "test.sqlite" runner = CliRunner() with runner.isolated_filesystem(): fifo_name = "jsonl_fifo" os.mkfifo(fifo_name) with ProcessPoolExecutor() as executor: executor.submit(fifo_writer, fifo_name) result = runner.invoke(cmd, ["-o", db_path, "file", fifo_name, "--format", "jsonl"]) print_traceback(result) assert result.exit_code == ExitCode.SUCCESS, fifo_name assert SimpleSQLite(db_path).fetch_num_records("jsonl_fifo") == 8
Example #2
Source File: webapp.py From kano-toolset with GNU General Public License v2.0 | 6 votes |
def thr_inject_javascript(browser, pipe_file): ''' This function reads from a pipe, a plain message interpreted as Javascript code. It then injects that code into the Webkit browser instance. From a bash script test it like this: $ echo "alert(\"Hello Kano\")" > /tmp/webapp.pipe TODO: collect and return synchronous error level? what about pipe security? ''' if os.path.exists(pipe_file): os.unlink(pipe_file) os.mkfifo(pipe_file) while True: f = open(pipe_file, 'r') pipe_data = f.read().strip('\n') asynchronous_gtk_message(browser.execute_script)(pipe_data) f.close()
Example #3
Source File: outputvideo.py From python-twitch-stream with MIT License | 6 votes |
def send_video_frame(self, frame): """Send frame of shape (height, width, 3) with values between 0 and 1. Raises an OSError when the stream is closed. :param frame: array containing the frame. :type frame: numpy array with shape (height, width, 3) containing values between 0.0 and 1.0 """ if self.video_pipe is None: if not os.path.exists('/tmp/videopipe'): os.mkfifo('/tmp/videopipe') self.video_pipe = os.open('/tmp/videopipe', os.O_WRONLY) assert frame.shape == (self.height, self.width, 3) frame = np.clip(255*frame, 0, 255).astype('uint8') try: os.write(self.video_pipe, frame.tostring()) except OSError: # The pipe has been closed. Reraise and handle it further # downstream raise
Example #4
Source File: conftest.py From python-libxdo with BSD 3-Clause "New" or "Revised" License | 6 votes |
def xterm_window(xvfb, tmpdir): """ Create an xterm window test fixture. This fixture opens a new xterm window and yields its the X window id. Upon test completion the xterm process is cleaned up. :param xvfb: :return: """ xterm_pipe_path = tmpdir.join('xterm_pipe').strpath xterm_proc = None try: os.mkfifo(xterm_pipe_path) xterm_proc = subprocess.Popen([ 'xterm', '-T', 'My window title', '-e', 'echo "$WINDOWID" > "{}"; bash'.format(xterm_pipe_path) ]) with open(xterm_pipe_path, 'r') as pipe: window_id = int(pipe.read()) yield XtermProcessInfo(proc=xterm_proc, window_id=window_id) finally: if xterm_proc: xterm_proc.terminate()
Example #5
Source File: test_shutil.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_copytree_named_pipe(self): os.mkdir(TESTFN) try: subdir = os.path.join(TESTFN, "subdir") os.mkdir(subdir) pipe = os.path.join(subdir, "mypipe") os.mkfifo(pipe) try: shutil.copytree(TESTFN, TESTFN2) except shutil.Error as e: errors = e.args[0] self.assertEqual(len(errors), 1) src, dst, error_msg = errors[0] self.assertEqual("`%s` is a named pipe" % pipe, error_msg) else: self.fail("shutil.Error should have been raised") finally: shutil.rmtree(TESTFN, ignore_errors=True) shutil.rmtree(TESTFN2, ignore_errors=True)
Example #6
Source File: __init__.py From script-languages with MIT License | 6 votes |
def import_via_exaplus(self, table_name, table_generator, prepare_sql): tmpdir = tempfile.mkdtemp() fifo_filename = os.path.join(tmpdir, 'myfifo') import_table_sql = '''IMPORT INTO %s FROM LOCAL CSV FILE '%s';'''%(table_name,fifo_filename) try: os.mkfifo(fifo_filename) write_trhead = threading.Thread(target=self._write_into_fifo, args=(fifo_filename, table_generator)) write_trhead.start() sql=prepare_sql+"\n"+import_table_sql+"\n"+"commit;" out,err=self.query_via_exaplus(sql) print(out) print(err) write_trhead.join() finally: os.remove(fifo_filename) os.rmdir(tmpdir)
Example #7
Source File: test_asserts.py From testpath with BSD 3-Clause "New" or "Revised" License | 6 votes |
def setUp(self): self.td = TemporaryDirectory() self.addCleanup(self.td.cleanup) self.file_path = os.path.join(self.td.name, 'afile') with open(self.file_path, 'w') as f: f.write('Blah') self.dir_path = os.path.join(self.td.name, 'adir') os.mkdir(self.dir_path) self.link_path = os.path.join(self.td.name, 'alink') self.pipe_path = os.path.join(self.td.name, 'apipe') self.socket_path = os.path.join(self.td.name, 'asocket') if os.name == 'posix': # Symlinks are rarely usable on Windows, because a special # permission is needed to create them. os.symlink(self.file_path, self.link_path) os.mkfifo(self.pipe_path) self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.sock.bind(self.socket_path) self.nonexistant_path = os.path.join(self.td.name, 'doesntexist')
Example #8
Source File: logs.py From cf-mendix-buildpack with Apache License 2.0 | 6 votes |
def set_up_logging_file(): util.lazy_remove_file("log/out.log") os.mkfifo("log/out.log") log_ratelimit = os.getenv("LOG_RATELIMIT", None) if log_ratelimit is None: subprocess.Popen( [ "sed", "--unbuffered", "s|^[0-9\-]\+\s[0-9:\.]\+\s||", "log/out.log", ] ) else: log_filter_thread = LogFilterThread(log_ratelimit) log_filter_thread.daemon = True log_filter_thread.start()
Example #9
Source File: eintr_tester.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def _test_open(self, do_open_close_reader, do_open_close_writer): filename = support.TESTFN # Use a fifo: until the child opens it for reading, the parent will # block when trying to open it for writing. support.unlink(filename) os.mkfifo(filename) self.addCleanup(support.unlink, filename) code = '\n'.join(( 'import os, time', '', 'path = %a' % filename, 'sleep_time = %r' % self.sleep_time, '', '# let the parent block', 'time.sleep(sleep_time)', '', do_open_close_reader, )) proc = self.subprocess(code) with kill_on_error(proc): do_open_close_writer(filename) self.assertEqual(proc.wait(), 0)
Example #10
Source File: test_shutil.py From BinderFilter with MIT License | 6 votes |
def test_copytree_named_pipe(self): os.mkdir(TESTFN) try: subdir = os.path.join(TESTFN, "subdir") os.mkdir(subdir) pipe = os.path.join(subdir, "mypipe") os.mkfifo(pipe) try: shutil.copytree(TESTFN, TESTFN2) except shutil.Error as e: errors = e.args[0] self.assertEqual(len(errors), 1) src, dst, error_msg = errors[0] self.assertEqual("`%s` is a named pipe" % pipe, error_msg) else: self.fail("shutil.Error should have been raised") finally: shutil.rmtree(TESTFN, ignore_errors=True) shutil.rmtree(TESTFN2, ignore_errors=True)
Example #11
Source File: userscripts.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
def prepare_run(self, *args, **kwargs): self._args = args self._kwargs = kwargs try: # tempfile.mktemp is deprecated and discouraged, but we use it here # to create a FIFO since the only other alternative would be to # create a directory and place the FIFO there, which sucks. Since # os.mkfifo will raise an exception anyways when the path doesn't # exist, it shouldn't be a big issue. self._filepath = tempfile.mktemp(prefix='qutebrowser-userscript-', dir=standarddir.runtime()) # pylint: disable=no-member,useless-suppression os.mkfifo(self._filepath, mode=0o600) # pylint: enable=no-member,useless-suppression except OSError as e: self._filepath = None # Make sure it's not used message.error("Error while creating FIFO: {}".format(e)) return self._reader = _QtFIFOReader(self._filepath) self._reader.got_line.connect(self.got_cmd) # type: ignore[arg-type]
Example #12
Source File: test_shutil.py From oss-ftp with MIT License | 6 votes |
def test_copytree_named_pipe(self): os.mkdir(TESTFN) try: subdir = os.path.join(TESTFN, "subdir") os.mkdir(subdir) pipe = os.path.join(subdir, "mypipe") os.mkfifo(pipe) try: shutil.copytree(TESTFN, TESTFN2) except shutil.Error as e: errors = e.args[0] self.assertEqual(len(errors), 1) src, dst, error_msg = errors[0] self.assertEqual("`%s` is a named pipe" % pipe, error_msg) else: self.fail("shutil.Error should have been raised") finally: shutil.rmtree(TESTFN, ignore_errors=True) shutil.rmtree(TESTFN2, ignore_errors=True)
Example #13
Source File: programs.py From raveberry with GNU Lesser General Public License v3.0 | 6 votes |
def start(self) -> None: self.current_frame = [0 for _ in range(self.bars)] self.growing_frame = b"" try: # delete old contents of the pipe os.remove(self.cava_fifo_path) except FileNotFoundError: # the file does not exist pass try: os.mkfifo(self.cava_fifo_path) except FileExistsError: # the file already exists logging.info("%s already exists while starting", self.cava_fifo_path) self.cava_process = subprocess.Popen( ["cava", "-p", os.path.join(settings.BASE_DIR, "config/cava.config")], cwd=settings.BASE_DIR, ) # cava_fifo = open(cava_fifo_path, 'r') self.cava_fifo = os.open(self.cava_fifo_path, os.O_RDONLY | os.O_NONBLOCK)
Example #14
Source File: test_posix.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_mkfifo(self): support.unlink(support.TESTFN) posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR) self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode))
Example #15
Source File: test_pathlib.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_is_fifo_true(self): P = self.cls(BASE, 'myfifo') os.mkfifo(str(P)) self.assertTrue(P.is_fifo()) self.assertFalse(P.is_socket()) self.assertFalse(P.is_file())
Example #16
Source File: test_stat.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_fifo(self): os.mkfifo(TESTFN, 0o700) st_mode, modestr = self.get_mode() self.assertEqual(modestr, 'prwx------') self.assertS_IS("FIFO", st_mode)
Example #17
Source File: test_shutil.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_copyfile_named_pipe(self): os.mkfifo(TESTFN) try: self.assertRaises(shutil.SpecialFileError, shutil.copyfile, TESTFN, TESTFN2) self.assertRaises(shutil.SpecialFileError, shutil.copyfile, __file__, TESTFN) finally: os.remove(TESTFN)
Example #18
Source File: test_csv_reader.py From pytablereader with MIT License | 5 votes |
def test_normal_fifo(self, tmpdir, table_text, fifo_name, expected): namedpipe = str(tmpdir.join(fifo_name)) os.mkfifo(namedpipe) loader = ptr.CsvTableFileLoader(namedpipe) with ProcessPoolExecutor() as executor: executor.submit(fifo_writer, namedpipe, table_text) for tabledata in loader.load(): print(dumps_tabledata(tabledata)) assert tabledata.in_tabledata_list(expected)
Example #19
Source File: test_posix.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_mkfifo_dir_fd(self): support.unlink(support.TESTFN) f = posix.open(posix.getcwd(), posix.O_RDONLY) try: posix.mkfifo(support.TESTFN, stat.S_IRUSR | stat.S_IWUSR, dir_fd=f) self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode)) finally: posix.close(f)
Example #20
Source File: pad.py From p3 with GNU General Public License v3.0 | 5 votes |
def __init__(self, path): """Create, but do not open the fifo.""" self.pipe = None self.path = path try: os.mkfifo(self.path) except OSError: pass
Example #21
Source File: pad_test.py From p3 with GNU General Public License v3.0 | 5 votes |
def setUp(self): # Create a fifo for testing. We'll remove it in tearDown. self.fifo_path = os.getcwd() + '/fifo' os.mkfifo(self.fifo_path) self.pipe = os.open(self.fifo_path, os.O_RDONLY | os.O_NONBLOCK) self.pad = p3.pad.Pad(self.fifo_path) self.pad.__enter__()
Example #22
Source File: tarfile.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def makefifo(self, tarinfo, targetpath): """Make a fifo called targetpath. """ if hasattr(os, "mkfifo"): os.mkfifo(targetpath) else: raise ExtractError("fifo not supported by system")
Example #23
Source File: tarfile.py From deepWordBug with Apache License 2.0 | 5 votes |
def makefifo(self, tarinfo, targetpath): """Make a fifo called targetpath. """ if hasattr(os, "mkfifo"): os.mkfifo(targetpath) else: raise ExtractError("fifo not supported by system")
Example #24
Source File: tarfile.py From pex with Apache License 2.0 | 5 votes |
def makefifo(self, tarinfo, targetpath): """Make a fifo called targetpath. """ if hasattr(os, "mkfifo"): os.mkfifo(targetpath) else: raise ExtractError("fifo not supported by system")
Example #25
Source File: tarfile.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def makefifo(self, tarinfo, targetpath): """Make a fifo called targetpath. """ if hasattr(os, "mkfifo"): os.mkfifo(targetpath) else: raise ExtractError("fifo not supported by system")
Example #26
Source File: tarfile.py From anpr with Creative Commons Attribution 4.0 International | 5 votes |
def makefifo(self, tarinfo, targetpath): """Make a fifo called targetpath. """ if hasattr(os, "mkfifo"): os.mkfifo(targetpath) else: raise ExtractError("fifo not supported by system")
Example #27
Source File: named_pipe.py From streamlink with BSD 2-Clause "Simplified" License | 5 votes |
def _create_fifo(self, name): os.mkfifo(name, 0o660)
Example #28
Source File: tarfile.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def makefifo(self, tarinfo, targetpath): """Make a fifo called targetpath. """ if hasattr(os, "mkfifo"): os.mkfifo(targetpath) else: raise ExtractError("fifo not supported by system")
Example #29
Source File: tarfile.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def makefifo(self, tarinfo, targetpath): """Make a fifo called targetpath. """ if hasattr(os, "mkfifo"): os.mkfifo(targetpath) else: raise ExtractError("fifo not supported by system")
Example #30
Source File: test_shutil.py From oss-ftp with MIT License | 5 votes |
def test_copyfile_named_pipe(self): os.mkfifo(TESTFN) try: self.assertRaises(shutil.SpecialFileError, shutil.copyfile, TESTFN, TESTFN2) self.assertRaises(shutil.SpecialFileError, shutil.copyfile, __file__, TESTFN) finally: os.remove(TESTFN)