File: thread.py

package info (click to toggle)
python-gevent 0.12.2-7
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,828 kB
  • ctags: 2,809
  • sloc: python: 9,151; makefile: 91; ansic: 42
file content (33 lines) | stat: -rw-r--r-- 960 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""implements standard module 'thread' with greenlets"""
__thread = __import__('thread')
from gevent.hub import getcurrent, GreenletExit, spawn_raw
from gevent.coros import Semaphore as LockType

def get_ident(gr=None):
    if gr is None:
        return id(getcurrent())
    else:
        return id(gr)

def start_new_thread(function, args=(), kwargs={}):
    greenlet = spawn_raw(function, *args, **kwargs)
    return get_ident(greenlet)

def allocate_lock():
    return LockType(1)

def exit():
    raise GreenletExit

if hasattr(__thread, 'stack_size'):
    _original_stack_size = __thread.stack_size
    def stack_size(size=None):
        if size is None:
            return _original_stack_size()
        if size > _original_stack_size():
            return _original_stack_size(size)
        else:
            pass
            # not going to decrease stack_size, because otherwise other greenlets in this thread will suffer

# XXX interrupt_main, _local