Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-backend / pithos / workers / monkey.py @ 809b482a

History | View | Annotate | Download (2.1 kB)

1 5dd1a322 Chrysostomos Nanakos
# -*- coding: utf-8 -
2 5dd1a322 Chrysostomos Nanakos
#
3 5dd1a322 Chrysostomos Nanakos
# Copyright 2013 GRNET S.A. All rights reserved.
4 5dd1a322 Chrysostomos Nanakos
#
5 5dd1a322 Chrysostomos Nanakos
# Redistribution and use in source and binary forms, with or
6 5dd1a322 Chrysostomos Nanakos
# without modification, are permitted provided that the following
7 5dd1a322 Chrysostomos Nanakos
# conditions are met:
8 5dd1a322 Chrysostomos Nanakos
#
9 5dd1a322 Chrysostomos Nanakos
#   1. Redistributions of source code must retain the above
10 5dd1a322 Chrysostomos Nanakos
#      copyright notice, this list of conditions and the following
11 5dd1a322 Chrysostomos Nanakos
#      disclaimer.
12 5dd1a322 Chrysostomos Nanakos
#
13 5dd1a322 Chrysostomos Nanakos
#   2. Redistributions in binary form must reproduce the above
14 5dd1a322 Chrysostomos Nanakos
#      copyright notice, this list of conditions and the following
15 5dd1a322 Chrysostomos Nanakos
#      disclaimer in the documentation and/or other materials
16 5dd1a322 Chrysostomos Nanakos
#      provided with the distribution.
17 5dd1a322 Chrysostomos Nanakos
#
18 5dd1a322 Chrysostomos Nanakos
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
19 5dd1a322 Chrysostomos Nanakos
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 5dd1a322 Chrysostomos Nanakos
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 5dd1a322 Chrysostomos Nanakos
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
22 5dd1a322 Chrysostomos Nanakos
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 5dd1a322 Chrysostomos Nanakos
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 5dd1a322 Chrysostomos Nanakos
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25 5dd1a322 Chrysostomos Nanakos
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 5dd1a322 Chrysostomos Nanakos
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 5dd1a322 Chrysostomos Nanakos
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 5dd1a322 Chrysostomos Nanakos
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 5dd1a322 Chrysostomos Nanakos
# POSSIBILITY OF SUCH DAMAGE.
30 5dd1a322 Chrysostomos Nanakos
#
31 5dd1a322 Chrysostomos Nanakos
# The views and conclusions contained in the software and
32 5dd1a322 Chrysostomos Nanakos
# documentation are those of the authors and should not be
33 5dd1a322 Chrysostomos Nanakos
# interpreted as representing official policies, either expressed
34 5dd1a322 Chrysostomos Nanakos
# or implied, of GRNET S.A.
35 5dd1a322 Chrysostomos Nanakos
36 5dd1a322 Chrysostomos Nanakos
37 5dd1a322 Chrysostomos Nanakos
from archipelago import common
38 5dd1a322 Chrysostomos Nanakos
from archipelago.common import posixfd_signal_desc
39 5dd1a322 Chrysostomos Nanakos
from ctypes import cast, POINTER
40 5dd1a322 Chrysostomos Nanakos
import os
41 5dd1a322 Chrysostomos Nanakos
from gevent import select
42 5dd1a322 Chrysostomos Nanakos
43 5dd1a322 Chrysostomos Nanakos
44 5dd1a322 Chrysostomos Nanakos
def pithos_xseg_wait_signal_green(ctx, sd, timeout):
45 5dd1a322 Chrysostomos Nanakos
    posixfd_sd = cast(sd, POINTER(posixfd_signal_desc))
46 5dd1a322 Chrysostomos Nanakos
    fd = posixfd_sd.contents.fd
47 8b1719d2 Chrysostomos Nanakos
    select.select([fd], [], [], timeout / 1000000.0)
48 5dd1a322 Chrysostomos Nanakos
    while True:
49 5dd1a322 Chrysostomos Nanakos
        try:
50 5dd1a322 Chrysostomos Nanakos
            os.read(fd, 512)
51 5dd1a322 Chrysostomos Nanakos
        except OSError as (e, msg):
52 5dd1a322 Chrysostomos Nanakos
            if e == 11:
53 5dd1a322 Chrysostomos Nanakos
                break
54 5dd1a322 Chrysostomos Nanakos
            else:
55 5dd1a322 Chrysostomos Nanakos
                raise OSError(e, msg)
56 5dd1a322 Chrysostomos Nanakos
57 5dd1a322 Chrysostomos Nanakos
58 5dd1a322 Chrysostomos Nanakos
def patch_Request():
59 5dd1a322 Chrysostomos Nanakos
    common.xseg_wait_signal_green = pithos_xseg_wait_signal_green