Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python线程、多处理或其他用于2个无限循环的数据传递_Python_Multiprocessing_Infinite Loop_Python Multithreading - Fatal编程技术网

Python线程、多处理或其他用于2个无限循环的数据传递

Python线程、多处理或其他用于2个无限循环的数据传递,python,multiprocessing,infinite-loop,python-multithreading,Python,Multiprocessing,Infinite Loop,Python Multithreading,当它在一个循环中时,一切正常,但在我看来,它必须是两个独立的循环。 (我们必须处理许多web客户端,并且只给它们一个完整的屏幕截图) 如何将实际数据从一个无限循环传递到另一个无限循环? 屏幕截图到web.py: index.html: 标题在这里。 这是一个更新的屏幕截图页面 页面闪烁应该怎么做? 我已经尝试过sone js,但没有一款是完美的。我想在Python上做一些类似的事情: from __future__ import print_function def make_scree

当它在一个循环中时,一切正常,但在我看来,它必须是两个独立的循环。 (我们必须处理许多web客户端,并且只给它们一个完整的屏幕截图)

如何将实际数据从一个无限循环传递到另一个无限循环?


屏幕截图到web.py: index.html:

标题在这里。
这是一个更新的屏幕截图页面

页面闪烁应该怎么做?
我已经尝试过sone js,但没有一款是完美的。

我想在Python上做一些类似的事情:
from __future__ import print_function

def make_screen_shots_forever(monitor_number=0,
                              file='screenShot.png',
                              delay_millisec = 1000.0,):
    import StringIO
    from time import sleep
    from desktopmagic.screengrab_win32 import (getDisplayRects, getRectAsImage)

    output = StringIO.StringIO()
    print("Start capturing...")
    while True:
        imDisplay = getRectAsImage(getDisplayRects()[monitor_number])
        imDisplay.save(output, format='png',optimize=True,quality=85)
        # contents needs to be send to web page
        contents = output.getvalue()
        sleep(delay_millisec/1000.0)
    return

# override one method used in SimpleHTTPRequestHandler
def copyfileobj(fsrc, fdst, length=1024*1024):
    """copy data from file-like object fsrc to file-like object fdst"""
    while 1:
        buf = fsrc.read(length)

        if not buf:
            break
        fdst.write(buf)

def start_web_server_forever(port = 8080):
    import SimpleHTTPServer
    import SocketServer
    from io import BytesIO

    #override standart handler
    class MyHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):

        # modify method
        def do_GET(self):
            """Serve a GET request."""
            f = self.send_head()
            if f:
                if 'screenShot.png' in self.path:
                    cont = BytesIO(make_one_shot())
                    try:
                        copyfileobj(cont,self.wfile)
                        #self.copyfile(cont, self.wfile)
                    finally:
                        cont.close()
                else:
                    try:
                        self.copyfile(f, self.wfile)
                    finally:
                        f.close()


    PORT = port

    httpd = SocketServer.TCPServer(("", PORT), MyHandler)
    print ("serving at port {}".format(PORT) )
    httpd.serve_forever()

def make_one_shot(monitor_number=0):
    imDisplay = getRectAsImage(getDisplayRects()[monitor_number])
    imDisplay.save(output, format='png',optimize=True,quality=85)
    contents = output.getvalue()
    return contents     



def main():
    from multiprocessing import Process, Lock, Value, Array

    # need to start both start_web_server_forever and make_screen_shots_forever in parallel
    # and pass contents data make_screen_shots_forever-->start_web_server_forever
    # when it is done (i mean complitly prepared)
    #make_screen_shots_forever()
    start_web_server_forever()



if __name__ == '__main__':
    main()
<html>
        <head>
            <title>Title goes here.</title>
                <meta charset="utf-8">
                <meta http-equiv="refresh" content="1">
        </head>
        <body>
            <p>This is an updating screenShot page.</p>
            <img src="screenShot.png" width=90%>
        </body>
</html>