Python for developers

I have submitted the following code as solution to the prime generator problem but haven’t been able to deal with the time constraint.
def pr(m,l,n):
prime = [True for i in range(l+2)]
p = 2
while (p * p <= l):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
for p in range(2, n):
if (p>=m and p<=l and prime[p]==True):
print(p,end=" ")

t=int(input())
while t>=1:
m, n=map(int,input().split( ))
pr(m,n,n-m)
print()
t=t-1
Can anyone suggest anything?