Giter Site home page Giter Site logo

pywpipe's Introduction

PyWPipe

This module makes it much cleaner and easier to use named pipes under Windows. It does not offer a feature rich API, but I may add more methods to support various other features such as setting the security of the pipe and support byte mode. At the moment only message mode is supported.

API

wpipe.Server(name, mode, *, maxclients = 5, maxmessagesz = 4096, maxtime = 100):
wpipe.Client(name, mode, *, maxmessagesz = 4096)

Examples

An example of a master and slave pipe mode.

import wpipe

The server code:

pserver = wpipe.Server('mypipe', wpipe.Mode.Slave)
while True:
    for client in pserver:
        while client.canread():
            rawmsg = client.read()
            client.write(b'hallo')    
    pserver.waitfordata()
pserver.shutdown()

The client code:

pclient = wpipe.Client('mypipe', wpipe.Mode.Master)
while True:
    pclient.write(b'hello')
    reply = pclient.read()
pclient.close()

The client blocks on pclient.read but you can perform a non-blocking operation by using pclient.canread before. The server client items are removed if the pipe is dead and no data can be read, so they will not be iterated over. For example if the client sent some data and then closed the connection the server could still read the data but any future reads would throw an exception.

In master and slave mode a single write or read is allowed before performing the opposite operation. The master writes a message and is then expected to read one message, and the slave reads one message and is expected to write one message.

You may notice the server is placed into slave mode and the client into master which may seem backwards however in some cases this is desired and useful. You could place the server into master mode and the client into slave mode.

Also Mode.Reader and Mode.Writer are supported making the pipe essentially uni-directional. I may in a future release tweak this to possibly allow a association method to tie together two pipes in this mode connected to a server.

pywpipe's People

Contributors

mark3982 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pywpipe's Issues

Cannot pip install

pip install PyWPipe does not work: I think this is because the package is registered on PyPI but you never uploaded an sdist. If you are interesed, I can write a simple setup.py and issue a PR to fix it.

wpipe.Server.shutdown is bool variable

Here is small code:

import wpipe
pipeserver = wpipe.Server('test', wpipe.Mode.Master)
print(repr(pipeserver))
print(repr(pipeserver.shutdown))
pipeserver.shutdown()

Here is output in console:

<wpipe.Server object at 0x02877870>
False
Traceback (most recent call last):
  File "test-pipe.py", line 9, in <module>
    pipeserver.shutdown()
TypeError: 'bool' object is not callable

That's because you have in constructor of the Server a line:

    self.shutdown = False

Also, the test script did not exit and just hang waiting me to hit Ctrl+Break.

Client and server blockingn forever

I created a fork for my own needs that fixes several issues, e.g. the server can be shut down and every I/O call has a timeout, but to make it work as expected I had to change most of the code, so I'm not making any pull request here to merge my changes, but if you are interested you can check out my new version and see if you want to include some or all of the changes in the main branch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.