from __future__ import absolute_import
import gevent.subprocess as subprocess
import gevent.socket as socket
from gevent.queue import Queue
from gevent.event import Event
from gevent import spawn

__all__="subprocess socket Queue Lock Event spawn serve_forever".split()

class Lock(object):
	def acquire(self, blocking=1):
		return True
	
	def noop(self, *args, **kwargs):
		pass
	
	release = noop
	__enter__ = noop
	__exit__ = noop


def serve_forever(*servers, **opts):
	for serv in servers:
		serv.start()
	
	try:
		opts.get("main", Event()).wait()
	finally:
		for serv in servers:
			serv.stop()


if __name__=="__main__":
	with Lock():
		r = spawn(lambda x: x, 1)
		assert r.get() == 1
	
	e = Event()
	def remote():
		e.set()
	r = spawn(remote)
	assert e.wait(0.5)
	assert r.get() == None
	r.join()


@@ -489,16 +489,22 @@
 vers:%0A%09%09
+spawn(
 serv.sta
@@ -505,17 +505,16 @@
 rv.start
-(
 )%0A%09%0A%09try
@@ -562,24 +562,53 @@
 ally:%0A%09%09for 
+job in %5Bspawn(serv.stop) for 
 serv in serv
@@ -614,22 +614,22 @@
 vers
+%5D
 :%0A%09%09%09
-serv.stop
+job.join
 ()%0A%0A

make gevent server start/stop parallel